hank-ger
Enthusiast
Enthusiast

How to get the VM UUID

Jump to solution

hi,

anybody know how to get the "UUID" with the VI-ToolKit?

thx

1 Solution

Accepted Solutions
ykalchev
VMware Employee
VMware Employee

Just get the vm using Get-VM or other cmdlet and then pass Id to Get-View cmdlet. Then you can examine all properties exposed by the VI API VirtualMachine managed object

Get-VM <vm_name> | %{(Get-View $_.Id).config.uuid}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team

View solution in original post

9 Replies
ykalchev
VMware Employee
VMware Employee

Just get the vm using Get-VM or other cmdlet and then pass Id to Get-View cmdlet. Then you can examine all properties exposed by the VI API VirtualMachine managed object

Get-VM <vm_name> | %{(Get-View $_.Id).config.uuid}

Regards,

Yasen

Yasen Kalchev, vSM Dev Team

View solution in original post

hank-ger
Enthusiast
Enthusiast

:smileylaugh: Thanks

0 Kudos
halr9000
Commander
Commander

Dumb question from a PowerShell expert but a relatively novice VMware guy--what is the UUID useful for?

(I like to think I've reached Journeyman status.)

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
hank-ger
Enthusiast
Enthusiast

We working with OSSV Backup. I want to make some helpfull scripts for the backup implementation.

0 Kudos
aw443
Contributor
Contributor

Its the Universal Unique Identifier.

If you ever moved a VM around, you may have seen a prompt in VMware Workstation, or in ESX, asking if you want to keep the old UUID or create a new one. If you kept it, it would keep the same MAC address, etc. The VM would be seen as the same even though it have been moved (or was a copy running somewhere else).

For me, keeping track of the UUID can be useful for tracking the VM; i.e. in situations where the VM is being moved around (whether san replication, backup/recovery purposes, SRM testing, etc) from one datacenter to another, for example. For me, it can be useful to compare the old VM and it's properties, with the newly copied one running in the new environment. Just an example.

There is probably a better use for keeping track of your VM UUID's. But thats why i've tried to maintain a record of them. The script can be very helpful. I've just copied the UUID field from a VC export.

0 Kudos
Hpapy_Gilmore10
Contributor
Contributor

There is probably a cleaner way of doing this but I'm just starting with the Powershell scripting but I had a bizarre scenario where I knew the UUID but not the VM name so I wrote this script to list all the VM's in my environment with their UUID and output it to a text file which I could simply search:

-


#CREATE FUNCTIONS

function Find_UUID

{

foreach($vm in $vmlist)

{

echo ""

echo "UUID For $vm "

echo "UUID For $vm " &gt;&gt; $file3

get-vm $vm | %{(Get-View $_.Id).config.uuid}

get-vm $vm | %{(Get-View $_.Id).config.uuid} &gt;&gt; $file3

echo ""

echo "" &gt;&gt; $file3

}

}

#SET VARIABLES

$file1 = "E:\VMScripts\Variables\VMList.txt"

$file2 = "E:\VMScripts\Variables\VMList_Clean.txt"

$file3 = "E:\VMScripts\Variables\VMList_UUID.txt"

echo ""

echo "Finding UUID For VM Script..."

echo ""

echo "Producting List Of VM's..."

echo ""

get-vm | select name &gt; $file1

echo "List Of VM's Produced"

(gc $file1) | foreach-object {$_ -replace " ", ""} | sc $file1

(gc $file2) | foreach-object {$_ -replace "Name", ""} | sc $file1

(gc $file2) | foreach-object {$_ -replace "----", ""} | sc $file1

cat $file1 | where {$_ -ne ""} &gt; $file2

$vmlist = Get-Content $file2

echo ""

echo "Find UUID"

echo "Find UUID" &gt; $file3

echo ""

Find_UUID

echo ""

echo "VM &gt; UUID List Produced"

-


0 Kudos
halr9000
Commander
Commander

Someone in the room has written more than his share of CMD batch files. 🙂




[vExpert|http://www.vmware.com/communities/vexpert/], PowerShell MVP, VI Toolkit forum moderator

Author of the book: Managing VMware Infrastructure with PowerShell

Co-Host, PowerScripting Podcast (http://powerscripting.net)

Need general, non-VMware-related PowerShell Help? Try the forums at PowerShellCommunity.org

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos
Hpapy_Gilmore10
Contributor
Contributor

My theory used to be that if you couldn't do it with a batch file, it probably wasn't worth doing! Smiley Happy

0 Kudos
LouisNdjouou
Contributor
Contributor

Very cool Thank you

Louis Ndjouou from ITOPSM, in Canada, delivering IT services

0 Kudos