News

Monday, July 16, 2012

Get the VMWare UUID's for multiple VM's in a .CSV file


# Save as GetUUIDs.ps1

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

Connect-VIServer $vc

CLS

'Beginning Script'
'Loading Snapins'
function LoadSnapin{
  param($PSSnapinName)
  if (!(Get-PSSnapin | where {$_.Name   -eq $PSSnapinName})){
    Add-pssnapin -name $PSSnapinName
  }
}
LoadSnapin -PSSnapinName   "VMware.VimAutomation.Core"

'Reading CSV file'
$vms = Import-CSV C:\Temp\GetUUIDs\computers.csv

$Tasks = @()

'Reading the contents of the CSV, and for each line execute the following code'
foreach ($vm in $vms){
# 'Declaring variables that correspond to the column names in the CSV'
    $VMName = $vm.name
   
    echo $VMName
Get-VM -name $VMName | %{(Get-View $_.Id).config.uuid}

                   }

Disconnect-VIServer $vc

No comments:

 
Free Hit Counter