VMware Cloud Community
halr9000
Commander
Commander

Removing serialport scsicontroller or other hardware devices

(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)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership

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 Smiley Wink

$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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership

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)}

}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
halr9000
Commander
Commander

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)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Reply
0 Kudos
LucD
Leadership
Leadership

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)}
}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
admin
Immortal
Immortal

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 Smiley Sad

Reply
0 Kudos