Change SCSI controller with PowerCLI on win 2008 R2 VM from Paravirtual

I found this KB 2004578 and thought that of course should this be done with PowerCLI

I made a function to be able to do it just by sending the VM parameter, it can be done if the VM is already shutdown with a simple one-liner

Get-VM v2vtest2 | Get-ScsiController | where {$_.Type -eq "Paravirtual"} | Set-ScsiController -Type VirtualLsiLogicSAS

But I wanted a more sophistical approach where my function shutdown the VM properly and then change the controller and starts the VM, the tricky part here was to check that the VM actually had shutdown before I change controller πŸ™‚

function Change-ScsiController{
<#
.SYNOPSIS
Stop a VM and replace the SCSI controller and start it again

.DESCRIPTION
Use this function to change scsi cntroller

.PARAMETER  xyz 

.NOTES
Author: Niklas Akerlund / RTS
Date: 2012-03-21
#>
    param (
   [Parameter(Position=0,Mandatory=$true,HelpMessage="A virtual machine",
    ValueFromPipeline=$True)]
    $VM
    )
	$VM = Get-VM $VM	
	
	Shutdown-VMGuest -VM $VM -Confirm:$false
	while ($VM.PowerState -eq "PoweredOn")
	{
	$VM = Get-VM $VM
	Start-Sleep -s 1	
	}
	Get-ScsiController -VM $VM | where {$_.Type -eq "Paravirtual"} | Set-ScsiController -Type VirtualLsiLogicSAS 
	Start-VM -VM $VM
	
}

Leave a comment

name*

email* (not published)

website