Automation

 View Only
Expand all | Collapse all

How to get the VM UUID

  • 1.  How to get the VM UUID

    Posted Jun 18, 2008 09:20 AM

    hi,

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

    thx



  • 2.  RE: How to get the VM UUID
    Best Answer

    Broadcom Employee
    Posted Jun 18, 2008 09:49 AM

    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



  • 3.  RE: How to get the VM UUID

    Posted Jun 18, 2008 11:02 AM

    :smileylaugh: Thanks



  • 4.  RE: How to get the VM UUID

    Posted Jun 18, 2008 01:00 PM

    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)



  • 5.  RE: How to get the VM UUID

    Posted Jun 18, 2008 02:01 PM

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



  • 6.  RE: How to get the VM UUID

    Posted Jun 24, 2008 11:31 PM

    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.



  • 7.  RE: How to get the VM UUID

    Posted Jun 16, 2009 05:06 PM

    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"

    -




  • 8.  RE: How to get the VM UUID

    Posted Jun 16, 2009 06:36 PM

    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



  • 9.  RE: How to get the VM UUID

    Posted Jun 16, 2009 06:39 PM

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



  • 10.  RE: How to get the VM UUID

    Posted Jul 14, 2015 09:32 PM

    Very cool Thank you

    Louis Ndjouou from ITOPSM, in Canada, delivering IT services



  • 11.  RE: How to get the VM UUID

    Posted Jan 19, 2022 11:20 AM

    If you want it a little bit more compact then the version from Hpapy_Gilmore10. Use this:

    Get-VM | Select-Object Name, @{ Name = "UUID"; Expression = {(Get-View $_.Id).config.uuid}}



  • 12.  RE: How to get the VM UUID

    Posted Aug 14, 2023 12:23 PM

    You may also take Name from .Config, and stick with either Get-VM or Get-View:

    or