2017-01-11 1 views
0

VMWare 환경의 모든 스냅 샷 목록을 가져 오는 중입니다. "VM, Name, Created, SizeGB"를 얻기 위해 목록을 포맷하고 있습니다. 이러한 VM에서 VM웨어 서버 태그 정보뿐만 아니라 어떻게해야할지 모르겠다. 태그 정보를 가져 와서 목록이 자체 포맷을 할 때 "SizeGB"아래에 배치하려고했습니다. 이것을 할 수있는 방법이 있습니까?VM 태그를 출력 텍스트 파일에 추가하는 방법

# 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 

답변

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

내가 이것을 사용하여 시도하고 더 출력이 아웃 파일 cmdlet를 제거하면 –

+0

당신이 콘솔의 출력을 볼 수 있습니까 파일에이 예정되지 않은 : 여기

는 태그 정보없이 내 스크립트입니다? 이것은 vCenter 5.5 및 PowerCLI 6.0에서 잘 작동합니다. – t1meless

+0

실제로 작동합니다! 고맙습니다! –

관련 문제