VMware Cloud Community
d00mfl1ght
Contributor
Contributor

How to extract VM UUIDs

Hello,

to create a script to make backup using NetApp snapshot manager for VI I need to extract periodically all VMs UUID along their own names...

This can be done using PowerCLI? Any hint?

Thanks

Ste

Tags (3)
0 Kudos
3 Replies
bulletprooffool
Champion
Champion

Powershell:

$vc = Read-Host "Please specify your VirtualCenter"

Connect-VIServer $vc

$VMHs = Get-VM

$myCol = @()

ForEach ($vmh in $vmhs)

{

$myObj = "" |

Select Name, UUID

$myObj.name = $vmh.name

$myObj.UUID = Get-VM $vmh.name | %{(Get-View $_.Id).config.uuid}

$myCol += $myObj

}

$myCol

One day I will virtualise myself . . .
0 Kudos
Sanit
Contributor
Contributor

Hi,

Is there a way to get VM names, their UUID according to resource pool?

Cheers,

Sanit

0 Kudos
jeveenj
Enthusiast
Enthusiast

Hi Sanit,

You can try below code snippet this will give you VM name, UUID and Resource Pool name.

$vc = Read-Host "Please specify your VirtualCenter"
Connect-VIServer $vc

$rps = Get-ResourcePool
ForEach ($rp in $rps)
{
     $VMHs = Get-VM -Location (Get-ResourcePool -Name $rp.name)
     $myCol = @()
     ForEach ($vmh in $vmhs)
     {
          $myObj = "" | 
          Select Name, UUID, RPname
          $myObj.Name = $vmh.name
          $myObj.UUID = Get-VM $vmh.name | %{(Get-View $_.Id).config.uuid}
          $myObj.RPname = $rp.name
          $myCol += $myObj
     }
     $myCol 
}

If you want to get from specific resourcepool , make changes as

Add $rpname = Read-Host "Please specify your Resourcepool" in place of "$rps = Get-ResourcePool"

Remove loop “ForEach ($rp in $rps)”

Replace $rp.name by $rpname in "$VMHs = Get-VM -Location (Get-ResourcePool -Name $rp.name)"

Remove “RPname” from “Select Name, UUID, RPname”

Remove “$myObj.RPname = $rp.name”

Hope this helps

-If you found this information useful, please consider awarding points for Correct or Helpful.
0 Kudos