-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndentify VMs.ps1
More file actions
47 lines (37 loc) · 1.9 KB
/
Indentify VMs.ps1
File metadata and controls
47 lines (37 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#######################################################################
# Identify VMs Uniquely Across Multiple vCenters
#######################################################################
# Author(s): Corey Blaz
# Github: https://github.com/blazcode
# Web: https://vcorey.com
# Connect to vCenter(s)
$creds = Get-Credential
Connect-VIServer -Server vcsa.lab.blaz.tech -Credential $creds -Force
#Connect-VIServer -Server vcsa2.example.com -Credential $creds -Force
$output = @()
$hasher = [System.Security.Cryptography.HashAlgorithm]::Create('sha256')
foreach ($vc in $global:DefaultVIServers) {
# Get the vCenter InstanceUUID
$vCenterInstanceUUID = ($vc.ExtensionData.Content.About.InstanceUuid)
$vms = Get-VM -Server $vc
foreach ($vm in $vms) {
# Hash combined VM vCenter InstanceUUID and VM InstanceUUIDs to create unique ID
$hash = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($vCenterInstanceUUID + $vm.ExtensionData.Config.InstanceUuid))
$globalIdSha = [System.BitConverter]::ToString($hash)
$vmData = [PSCustomObject]@{
vCenterName = $vc.Name
vCenterInstanceUUID = $vCenterInstanceUUID
VM_Name = $vm.Name
VM_MoRef = $vm.Id #VM MoRef
VM_InstanceUUID = $vm.ExtensionData.Config.InstanceUuid #VM InstanceUUID
VM_BiosUUID = $vm.ExtensionData.Config.Uuid
#VM_GlobalUniqueId = $vCenterInstanceUUID + " + " + $vm.ExtensionData.Config.InstanceUuid #Example for illustrative purposes
#VM_GlobalUniqueId_SHA256 = $globalIdSha.Replace('-', '')
}
$output += $vmData
}
}
#Disconnect-VIServer * -Confirm:$false
# Display and export the output
$output | Format-Table -AutoSize
$output | Export-Csv -Path /Users/cblaz/Downloads/vm-unique-ids.csv -NoTypeInformation