VMware Cloud Community
gman7777
Contributor
Contributor
Jump to solution

does anyone havea script to Update VMGuest Hardware

Hi Everyone,

This is what I am trying to find if anyone could help, that would be great.

1. A script to shutdown certain VMGuests. (Only VMguests from a list I provide)

2. the upgrade of hardware for the sames guests

3. Power on after hardware upgrade is complete

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

The .txt file contains the vm names, one per line.

$vmNames = Get-Content -Path vmnames.txt

$vms = Get-VM -Name $vmNames

foreach($vm in $vms){

    Stop-VMGuest -VM $vm

    while($vm.PowerState -ne 'PoweredOff'){

        $vm = Get-VM -Name $vm.Name

        sleep 5

    }

    Set-VM -VM $vm -Version v10 -Confirm:$false

    Start-VM -VM $vm -Confirm:$false

}


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this.

The .txt file contains the vm names, one per line.

$vmNames = Get-Content -Path vmnames.txt

$vms = Get-VM -Name $vmNames

foreach($vm in $vms){

    Stop-VMGuest -VM $vm

    while($vm.PowerState -ne 'PoweredOff'){

        $vm = Get-VM -Name $vm.Name

        sleep 5

    }

    Set-VM -VM $vm -Version v10 -Confirm:$false

    Start-VM -VM $vm -Confirm:$false

}


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

Reply
0 Kudos
gman7777
Contributor
Contributor
Jump to solution

Hi Luc,

This script is awesome. Thank You. Onyly one question though. I have tested this on one VM, and it prompted me for a response to perform the action of shutting down, if which I had to ansewr YES. If I have multiple VMs, would I have to repeat answering for each VM? Alternately, is there a force response that could be added to the script

I hope that makes sense

Reply
0 Kudos
gman7777
Contributor
Contributor
Jump to solution

figured it out with -Confirm$false

Thanks again

Reply
0 Kudos