Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 49146

Re: Get VM Generation ID from powershell

$
0
0

Thanks, I forgot about that one. Do you think there is anyway to improve this? So far it works and it pretty quick I'm going to try and find ways to change these manually. I'm planning on adding custom monitor to the vms that use licensing based on this.

 

$vmname="name of vm"

$olduuid=""

$oldmacs=""

$olddiskuuid=""

$oldvmgenid=""

$oldvmgenidx=""

if((Test-Path C:\users\sjesse\$vmname-uuid.xml))

{

    $olduuid=Import-Clixml C:\users\sjesse\$vmname-uuid.xml

    $oldmacs=Import-Clixml C:\users\sjesse\$vmname-macs.xml

    $olddiskuuid=Import-Clixml C:\users\sjesse\$vmname-diskuuid.xml

    $oldvmgenid=Import-Clixml C:\users\sjesse\$vmname-genid.xml

    $oldvmgenidx=Import-Clixml C:\users\sjesse\$vmname-genidx.xml

}

 

 

#get vm uuid

$vm=get-vm $vmname| get-view | select @{l="uuid";e={$_.config.instanceuuid}}

$uuid=$vm.uuid

#get vm mac addresses

$macaddress= get-vm $vmname | Get-NetworkAdapter | select -ExpandProperty MacAddress

#get vm disk uuids

$diskuuid= get-vm $vmname | Get-HardDisk |

 

 

Select @{N='VM';E={$_.Parent.Name}},

 

 

    @{N='Harddisk';E={$_.Name}},

 

 

    @{N='Uuid';E={$_.ExtensionData.Backing.Uuid}}

#get vm gen ids

$vmgenid=Get-AdvancedSetting -Entity $vmname -Name "Vm.genid"

$vmgenidx=Get-AdvancedSetting -Entity $vmname -Name "Vm.genidx"

 

 

if($olduuid -ne $uuid)

{

    Write-Host $vmname "uuid changed from $olduuid to $uuid"

    $olduuid

    $uuid

}

if(@(Compare-Object $macaddress $oldmacs -SyncWindow 0).Length -ne 0)

{

    Write-Host $vmname "a mac address changed"

}

if(@(Compare-Object $diskuuid $olddiskuuid -SyncWindow 0).Length -ne 0)

{

    Write-Host $vmname "a disk uuid changed"

}

if(@(Compare-Object $vmgenid.Value $oldvmgenid.Value -SyncWindow 0).Length -ne 0)

{

    Write-Host $vmname "Generiation ID changed"

}

if(@(Compare-Object $vmgenidx.Value $oldvmgenidx.Value -SyncWindow 0).Length -ne 0)

{

    Write-Host $vmname "Generiation ID changed"

}

 

 

$uuid | Export-Clixml C:\users\sjesse\$vmname-uuid.xml

$macaddress | Export-Clixml C:\users\sjesse\$vmname-macs.xml

$diskuuid | Export-Clixml C:\users\sjesse\$vmname-diskuuid.xml

$vmgenid | Export-Clixml C:\users\sjesse\$vmname-genid.xml

$vmgenidx | Export-Clixml C:\users\sjesse\$vmname-genidx.xml


Viewing all articles
Browse latest Browse all 49146

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>