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

1Get-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 🙂

01function Change-ScsiController{
02<#
03.SYNOPSIS
04Stop a VM and replace the SCSI controller and start it again
05 
06.DESCRIPTION
07Use this function to change scsi cntroller
08 
09.PARAMETER  xyz 
10 
11.NOTES
12Author: Niklas Akerlund / RTS
13Date: 2012-03-21
14#>
15    param (
16   [Parameter(Position=0,Mandatory=$true,HelpMessage="A virtual machine",
17    ValueFromPipeline=$True)]
18    $VM
19    )
20    $VM = Get-VM $VM   
21     
22    Shutdown-VMGuest -VM $VM -Confirm:$false
23    while ($VM.PowerState -eq "PoweredOn")
24    {
25    $VM = Get-VM $VM
26    Start-Sleep -s 1   
27    }
28    Get-ScsiController -VM $VM | where {$_.Type -eq "Paravirtual"} | Set-ScsiController -Type VirtualLsiLogicSAS 
29    Start-VM -VM $VM
30     
31}

Leave a comment

name*

email* (not published)

website