VMware Cloud Community
Arkady
Contributor
Contributor

Script to change Guest OS and version

Hello,

We are upgrading VMs from Windows 7 to Windows 10, and need to change Guest OS and version after the upgrade on multiple VMs.

Looking for a script to automate it.

Thank you in advance!

0 Kudos
5 Replies
LucD
Leadership
Leadership

Something like this?

$vm = Get-VM -Name MyVM


$spec = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec

$spec.GuestId = [VMware.Vim.VirtualMachineGuestOsIdentifier]::windows9_64Guest

$vm.ExtensionData.ReconfigVM($spec)


$vm.ExtensionData.UpgradeVM('vmx-15')


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

0 Kudos
Arkady
Contributor
Contributor

Hello Luc,

Thank you, How can it run against a list of VMs?

0 Kudos
LucD
Leadership
Leadership

You could do something like this.

This assumes that the .TXT file contains 1 VMname per line.

$spec = New-Object -TypeName VMware.Vim.VirtualMachineConfigSpec

$spec.GuestId = [VMware.Vim.VirtualMachineGuestOsIdentifier]::windows9_64Guest


Get-VM -Name (Get-Content -Path .\vmnames.txt) |

ForEach-Object -Process {

   $_.ExtensionData.ReconfigVM($spec)

   $_.ExtensionData.UpgradeVM('vmx-15')

}


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

0 Kudos
Arkady
Contributor
Contributor

Hello Luc,

What does this line do?

.ExtensionData.UpgradeVM('vmx-15')

0 Kudos
LucD
Leadership
Leadership

It calls the UpgradeVM API method on the VM.

The string parameter specifies which HW version to upgrade to.

$vm.ExtensionData.UpgradeVM('vmx-15')


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

0 Kudos