VMware Cloud Community
internetrush1
Contributor
Contributor

Remove-SCSIController?

http://blogs.vmware.com/vipowershell/2010/12/support-for-virtual-machine-scsi-controllers-in-powercl...

Referenceing the above, there is no cmdlet similar to the subject line; however, i have a few dozen servers that just got 17 drives removed and need their SCSI controllers removed as well. Why do they not get automatically removed and is there a way to remove them?

Thanks!

0 Kudos
4 Replies
LucD
Leadership
Leadership

Are you sure there is no device still connected to the SCSI controller ?

Like the blogpost says, once you remove the last device, the SCSI controller will be removed as well.

In what powerstate are the VMs ?

Did you try a poweroff/poweron for the VM ?


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

internetrush1
Contributor
Contributor

THe VM was powered on at the time that this was done, THis was all done in POWERCLI 5.0.1.

Did nto attempt to powercycle them, too bad the blog does not specify :smileysilly:.

0 Kudos
adamflaig1
Enthusiast
Enthusiast

I know this is an older post but I was able to still duplicate this issue in PowerCLi 6.5.

I migrated the drives to a new controller and the older controller still persisted through multiple power cycles. 

To remove the controller as expected after migrating production drives to a new controller I performed the following steps:

  1. power off the VM
  2. Added new hard disk to the stuck controller.
  3. power on/off
  4. remove new hard disk
  5. controller should be gone

  

$origController = get-scsicontroller -VM $testVM

$testVM | stop-VM -confirm:$false

Get-HardDisk -VM $testVM | New-ScsiController -type ParaVirtual

$testVM | start-VM -confirm:$false

$testVM | stop-VM -confirm:$false

$tmpDisk = new-Hard-disk -controller $origController -capacityKB 1000000

$tmpDisk | remove-HardDisk -confim:$false

$testVM | start-VM -confirm:$false

Adam Flaig
0 Kudos
Dharzhak
Enthusiast
Enthusiast

Yeah, it's a simple thing to reproduce. 

I wrote a fairly simple function that uses the same syntax as the existing Set-ScsiController. Strictly speaking, you can remove unused SCSI controllers from running VMs, but we weren't comfortable with that. If you are, you can remove that check.

function Remove-ScsiController {

    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]

    Param(

        [Parameter (

            ValueFromPipeline = $true,

            ValueFromPipelineByPropertyName = $true,

            Mandatory = $true

        )]

        [ValidateNotNullOrEmpty()]

        [VMware.VimAutomation.ViCore.Impl.V1.VIObjectImpl[]]$ScsiController

    )

    Process {

        foreach ($ControllerObj in $ScsiController) {

            if ($ControllerObj.GetType().Name -ne 'ScsiControllerImpl') {

                Write-Error "$($ControllerObj.Name): Invalid object type $($ControllerObj.GetType().Name)."

            }

            else {

                $VMObj = $ControllerObj.Parent

                # Verify VM is powered off

                if ($VMObj.PowerState -eq 'poweredOn') {

                    Write-Error "Unable to modify $($VMObj.Name). Please power VM off."

                }

                # Verify specified SCSI controllers do not have attached disks

                elseif ($ControllerObj.ExtensionData.Device) {

                    Write-Error "$($ControllerObj.Name) has attached disks."

                }

                # If confirmed to proceed, remove the controller

                elseif ($PSCmdlet.ShouldProcess($ControllerObj)) {

                    $NewSpec = New-Object -Type VMware.Vim.VirtualMAchineConfigSpec

                    $DeviceSpec = New-Object VMware.Vim.VirtualDeviceConfigSpec

                    $DeviceSpec.Device = $ControllerObj.ExtensionData

                    $DeviceSpec.Operation = "remove"

                    $NewSpec.DeviceChange = $DeviceSpec

                    $VMObj.ExtensionData.ReconfigVM_Task($NewSpec)

                }

            }

        }

    }

}

0 Kudos