Problema
Recentemente mi è capitato di dover recuperare velocemente tramite script PowerShell alcune informazioni come:
Soluzione
Di seguito lo script in powershell per fare questo.
That's it!
Recentemente mi è capitato di dover recuperare velocemente tramite script PowerShell alcune informazioni come:
- Nome Virtual Machine (Inventario vCenter)
- Sistema Operativo
- Indirizzo IP
- Nome host della VM (FQDN)
- Indirizzo MAC
Soluzione
Di seguito lo script in powershell per fare questo.
Connect-VIServer -Server <VCSA> -User <Userrname> -Password <Password>
$DTC = "<Datacenter>"
$Report = @()
ForEach ($VM in (Get-Datacenter $DTC) | Get-VM) {
$tempvm=@{}
$tempvm.Name = $VM.Name
$tempvm.GuestOS = If (!$VM.Guest.OSFullName) {"Tools Not Running\Unknown"} Else {$VM.Guest.OSFullName}
$tempvm.IP = If (!$VM.Guest.IPAddress[0]) {"Tools Not Running\Unknown"} Else {$VM.Guest.IPAddress[0]}
$tempvm.FullName = If (!$VM.Guest.hostname) {"Tools Not Running\Unknown"} Else {$VM.Guest.hostname}
$tempvm.MacAddress = (Get-NetworkAdapter -VM $VM.Name).MacAddress
#$tempvm.CustomFields = $VM.CustomFields
$temp = New-Object -TypeName PSObject -Property $tempvm
$Report += $temp
}
$Report | Select Name, GuestOS, IP, FullName, MacAddress | Sort Name | Format-Table -AutoSize #Output on Screen
#$Report | Select Name, GuestOS, IP, FullName, MacAddress | Sort Name | export-csv ".\Export-VMInfo.csv" #Output on file
Come possibile vedere dallo script sopra, l'output viene mostrato in formato tabella direttamente a video, ma può anche essere esportato e salvato in un file .CSV.
That's it!

Nessun commento:
Posta un commento