Automation

 View Only
  • 1.  Removing serialport scsicontroller or other hardware devices

    Posted Apr 04, 2008 01:35 PM

    (another split from )

    How about "New-SerialPort" "Remove-SerialPort", ditto Parallel port, ditto USB Controller (particularly the remove!) ?

    Also "Set-SCSIController" to change the type between BusLogic and LSI

    (I'm using a powershell script using the VI toolkit and P2VTOOL.exe to hot clone production servers to a DR Cluster. I'd like to be able to remove uneccessary serial\parallel\usb ports and correct the SCSI Controller otherwise we have to do it manually in a DR situation)

    Thanks

    Andrew

    Hal Rottenberg

    Co-Host, PowerScripting Podcast (http://powerscripting.net)



  • 2.  RE: Removing serialport scsicontroller or other hardware devices

    Posted Apr 05, 2008 12:34 AM

    This is something I used to remove serial and parallel ports from guests.

    It shoudl be straightforward to use a similar flow to change the SCSI controller type this way.

    The "operation" has to be changed to "edit" in that case.

    Note that this is something quick-and-dirty. I leave it to the PowerShell gurus to "beautify" it... Hal :smileywink:

    $VMs = Get-VM

    foreach ($VMimpl in $VMs){

    $VM = Get-View $VMimpl.ID

    $i = 0

    $spec = new-object VMware.Vim.VirtualMachineConfigSpec

    $HW = $VM.Config.Hardware.Device

    foreach($dev in $HW){

    if (($dev.DeviceInfo.Label -like "Parallel Port *") -or

    ($dev.DeviceInfo.Label -like "Serial Port *"))

    {

    $spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec

    $spec.DeviceChange[$i].device = New-Object VMware.Vim.VirtualDevice

    $spec.DeviceChange[$i].device.key = $dev.Key

    $spec.DeviceChange[$i].operation = "remove"

    $i++

    }

    }

    if ($i -gt 0) {$VM.ReconfigVM_Task($spec)}

    }

    PS: as far as I know ESX doesn't support USB devices for guests like Workstation does



  • 3.  RE: Removing serialport scsicontroller or other hardware devices

    Posted Apr 05, 2008 01:01 AM

    It seems the forum SW changed some lines in the script.

    I placed the affected lines between code markups

    $VMs = Get-VM

    foreach ($VMimpl in $VMs){

    $VM = Get-View $VMimpl.ID

    $i = 0

    $spec = new-object VMware.Vim.VirtualMachineConfigSpec

    $HW = $VM.Config.Hardware.Device

    foreach($dev in $HW){

    if (($dev.DeviceInfo.Label -like "Parallel Port *") -or

    ($dev.DeviceInfo.Label -like "Serial Port *"))

    {

    $spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec

    $spec.DeviceChange[$i].device = New-Object VMware.Vim.VirtualDevice

    $spec.DeviceChange[$i].device.key = $dev.Key

    $spec.DeviceChange[$i].operation = "remove"

    $i++

    }

    }

    if ($i -gt 0) {$VM.ReconfigVM_Task($spec)}

    }



  • 4.  RE: Removing serialport scsicontroller or other hardware devices

    Posted Apr 05, 2008 01:09 AM

    Sweet! Hey LucD, can you edit your post and place #code goes here tags around it? Remove the spaces between the word and the braces to make it work.

    Hal Rottenberg

    Co-Host, PowerScripting Podcast (http://powerscripting.net)



  • 5.  RE: Removing serialport scsicontroller or other hardware devices

    Posted Apr 05, 2008 07:07 AM

    The lines become one long line in a code block/paragraph

    Aren't there any meta text instructions to keep it as entered ?

    $VMs = Get-VM
    foreach ($VMimpl in $VMs){
    $VM = Get-View $VMimpl.ID
    $i = 0
    $spec = new-object VMware.Vim.VirtualMachineConfigSpec
    
    $HW = $VM.Config.Hardware.Device
    foreach($dev in $HW){
    if (($dev.DeviceInfo.Label -like "Parallel Port *") -or
    ($dev.DeviceInfo.Label -like "Serial Port *")) 
    {
    $spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec
    $spec.DeviceChange[$i].device = New-Object VMware.Vim.VirtualDevice
    
    $spec.DeviceChange[$i].device.key = $dev.Key
    
    $spec.DeviceChange[$i].operation = "remove" 
    
    $i++
    }
    }
    if ($i -gt 0) {$VM.ReconfigVM_Task($spec)}
    }
    



  • 6.  RE: Removing serialport scsicontroller or other hardware devices

    Posted Apr 07, 2008 04:51 PM

    The lines become one long line in a code block/paragraph

    Aren't there any meta text instructions to keep it as entered ?

    The lines render properly in FF. The Jive people evidently haven't heard of IE :smileysad: