Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何将VM标记添加到输出文本文件中_Powershell_Powercli - Fatal编程技术网

Powershell 如何将VM标记添加到输出文本文件中

Powershell 如何将VM标记添加到输出文本文件中,powershell,powercli,Powershell,Powercli,我正在获取VMWare环境中所有快照的列表,我正在格式化该列表以获取“VM、Name、Created、SizeGB”,我还希望从这些VM获取VMWare服务器标记信息,但我不确定如何执行此操作。我想获取标签信息,并在列表格式化时将其放在“SizeGB”下。有办法做到这一点吗 这是我的脚本,没有标签信息: # Adding PowerCLI Snap-in to use cmdlets to connect to vSphere Add-PSSnapin VMware.VimAutomation.

我正在获取VMWare环境中所有快照的列表,我正在格式化该列表以获取“VM、Name、Created、SizeGB”,我还希望从这些VM获取VMWare服务器标记信息,但我不确定如何执行此操作。我想获取标签信息,并在列表格式化时将其放在“SizeGB”下。有办法做到这一点吗

这是我的脚本,没有标签信息:

# 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

我尝试使用此命令,但没有输出到文件。如果使用remove-Out-File cmdlet,在控制台中是否看到任何输出?对于我来说,使用vCenter 5.5和PowerCLI 6.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