VMware Cloud Community
daphnissov
Immortal
Immortal
Jump to solution

Change vcuuid

Does anyone have some example code that changes the vc.uuid of a VM? Either an arbitrary value or random generator would be fine.

Reply
0 Kudos
1 Solution

Accepted Solutions
daphnissov
Immortal
Immortal
Jump to solution

I may have figured out a solution after reading this pointer. By passing an empty string, the API appears to randomly generate its own instanceUuid. I used the following and it seemed to generate a new vc.uuid:

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.instanceUuid =  ''

$vm = Get-VM -Name $vmName

$vm.Extensiondata.ReconfigVM_Task($spec)

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

$vmName = 'MyVM'

$left = (1..8 | %{'{0:X2}'-f (Get-Random -Maximum 255)}) -join ' '

$right = (1..8 | %{'{0:X2}'-f (Get-Random -Maximum 255)}) -join ' '

$newUuid = $left,$right -join '-'

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.uuid = $newUuid

$vm = Get-VM -Name $vmName

$vm.Extensiondata.ReconfigVM_Task($spec)


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

daphnissov
Immortal
Immortal
Jump to solution

Thanks much for that, LucD​. This code changes the uuid.bios value, but what I'm trying to accomplish is changing the vc.uuid value of a given VM. Does VMware.Vim.VirtualMachineConfigSpec accept a type of .vcuuid where I could use that instead of uuid?

Reply
0 Kudos
nicholas1982
Hot Shot
Hot Shot
Jump to solution

Does this give you the VC.uuid

(Get-VM MyVM | Select -first 1).extensiondata.config.InstanceUUID

Nicholas
Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

Yes, and I tried $spec.instanceuuid and the command executes successfully but a vCenter error results that a specified parameter is incorrect.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

After several attempts and research online, I can't figure out how to set instanceUuid on a given VM even though the format is the same as Uuid.

Reply
0 Kudos
daphnissov
Immortal
Immortal
Jump to solution

I may have figured out a solution after reading this pointer. By passing an empty string, the API appears to randomly generate its own instanceUuid. I used the following and it seemed to generate a new vc.uuid:

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.instanceUuid =  ''

$vm = Get-VM -Name $vmName

$vm.Extensiondata.ReconfigVM_Task($spec)

Reply
0 Kudos