2017-01-11 2 views
0

Ich bekomme eine Liste aller Snapshots in meiner VMWare-Umgebung und ich formatiere die Liste zu "VM, Name, Created, SizeGB" und ich möchte auch bekommen Die vmware-Server-Tag-Informationen von diesen VMs auch, aber ich bin mir nicht sicher, wie dies zu tun ist. Ich wollte die Tag-Informationen abrufen und sie unter "SizeGB" platzieren, wenn sich die Liste selbst formatiert. Gibt es eine Möglichkeit, dies zu tun?Wie bekomme ich VM-Tags in meine Ausgabe Textdatei hinzugefügt

Hier ist mein Skript ohne das Tag Info:

# Adding PowerCLI Snap-in to use cmdlets to connect to vSphere 
Add-PSSnapin VMware.VimAutomation.Core 

# Connect to vCenter 
Connect-ViServer -server $vCenter -ErrorAction Stop 

# Write header on report 
Write-Output "VMWare Snapshot Report for $(get-date -f MM-dd-yyyy)" | 
    Out-File $Log -Append 

# Get VM Snapshot Information for all Snapshots and send that information to 
# c:\automation\AllSnapshots.txt 
Get-VM | Get-Snapshot | Where-Object { 
    $_.Created -lt (Get-Date).AddDays(-3) 
} | Format-List vm, name, created, sizegb | Out-File $Log -Append 

# Disconnect from vCenter 
Disconnect-VIServer -Server * -Force -Confirm:$false 

Antwort

0
# Adding PowerCLI Snap-in to use cmdlets to connect to vSphere 
Add-PSSnapin VMware.VimAutomation.Core 

# Connect to vCenter 
Connect-ViServer -server $vCenter -ErrorAction Stop 

# Write header on report 
Write-Output "VMWare Snapshot Report for $(get-date -f MM-dd-yyyy)" | 
    Out-File $Log -Append 

# Get VM Snapshot Information for all Snapshots and send that information to 
# c:\automation\AllSnapshots.txt 
$output = @() 
foreach ($vm in Get-VM) { 
    $tags = ((Get-TagAssignment -Entity $vm | select -ExpandProperty Tag).Name -join ", ") 
    foreach ($snapshot in $vm | Get-Snapshot | Where-Object { $_.Created -lt (Get-Date).AddDays(-3) }) { 
     $obj = [PSCustomObject]@{VM = $vm.Name; Name = $snapshot.Name; Created = $snapshot.Created; SizeGB = $snapshot.SizeGB; Tags = $tags} 
     $output += $obj 
    } 
} 
$output | Format-List | Out-File $Log -Append 

# Disconnect from vCenter 
Disconnect-VIServer -Server * -Force -Confirm:$false 
+0

Ich habe versucht, dies mit und es wird keine Ausgabe an die Datei gehen –

+0

Sie eine Ausgabe in der Konsole sehen Sie, wenn Cmdlet Out-File entfernen? Das funktioniert für mich mit vCenter 5.5 und PowerCLI 6.0. – t1meless

+0

Wirklich es funktioniert! Vielen Dank! –

Verwandte Themen