Hi LucD,
follow the final script that is helpfull for my question, many thanks. (sorry I don't know how to put color as your replies)
if ($vrvmname01 -eq "")
{
$vrvmsinobj = get-folder -name "foldersvms" | get-vm
Write-Host "CHECK UUID ALL VMs" -ForegroundColor Black -BackgroundColor Yellow
foreach ($vrvminobj in $vrvmsinobj)
{
""
""
Get-VM -Name $vrvminobj | Get-HardDisk |
Select @{N='VM';E={$_.Parent.Name}},
@{N='Harddisk';E={$_.Name}},
@{N='Uuid';E={$_.ExtensionData.Backing.Uuid}},
@{N='Path';E={$_.FileName.Split("/")[1].TrimStart("")}},
@{N='Capacity';E={$_.CapacityGB}} |
Format-Table -AutoSize
}
}
else {
""
"________________________________________________________"
""
Write-Host "Verifica UUID $vrvmname01" -ForegroundColor Black -BackgroundColor Yellow
"________________________________________________________"
$vrvmname01state = Get-VM -Name $vrvmname01 | Select PowerState -ExpandProperty PowerState
if ($vrvmname01state -eq "PoweredOn")
{
"________________________________________________________"
""
Write-Host "$vrvmname01 è ACCESA" -ForegroundColor Yellow
"________________________________________________________"
"________________________________________________________________________________________________"
""
}
Get-VM -Name $vrvmname01 | Get-HardDisk |
Select @{N='VM';E={$_.Parent.Name}},
@{N='Harddisk';E={$_.Name}},
@{N='Uuid';E={$_.ExtensionData.Backing.Uuid}},
@{N='Path';E={$_.FileName.Split("/")[1].TrimStart("")}},
@{N='Capacity';E={$_.CapacityGB}} |
Format-Table -AutoSize
"________________________________________________________________________________________________"
}
$vrdsname01 = Get-VM -Name $vrvmname01 | Get-HardDisk | %{$_.FileName.Split("]")[0].TrimStart("[")} | Select -First 1
$vrds01 = Get-Datastore -Name $vrdsname01
$vrsi = Get-View ServiceInstance
$vrvmdkmgr = Get-View -Id $vrsi.Content.VirtualDiskManager
$vrexfile = @('*-flat.vmdk','*-ctk.vmdk')
New-PSDrive -Datastore $vrds01 -Name DS -PSProvider vimdatastore -Root '\' | Out-Null
""
""
"________________________________________________________"
""
Write-Host "Verifica UUID tutti i vmdk con nome: "$vrvmname01"" -ForegroundColor Black -BackgroundColor Yellow
"________________________________________________________"
"______________________________________________________________________________________________________________________"
Get-ChildItem -Path DS: -Recurse -Filter "$vrvmname01*.vmdk" -Exclude $vrexfile |
ForEach-Object -Process {
$vc = $_.FullName.Split('\')[1].Split('@')[0]
$dummy,$dc,$vrds01,$path = $_.FullName.Split('@')[1].Split('\',[System.StringSplitOptions]::RemoveEmptyEntries)
$path = $path -join '/'
$uri = "https://$vc/folder/$($path)?dcPath=$dc&dsName=$vrds01"
$hexUuid = $vrvmdkmgr.QueryVirtualDiskUuid($uri,$null)
$hexUuid = $hexUuid.Split(' -')
[pscustomobject]@{
File = $_.DatastoreFullPath
Uuid = "{0:x8}-{1:x4}-{2:x4}-{3:x4}-{4:x12}" -f ($hexUuid[0..3] -join ''),
($hexUuid[4..5] -join ''),
($hexUuid[6..7] -join ''),
($hexUuid[8..9] -join ''),
($hexUuid[10..15] -join '')
}
} | Sort-Object -Property File
"______________________________________________________________________________________________________________________"
Remove-PSDrive -Name DS -Confirm:$false