我想将 get-vmhost 的输出放到带有时间戳的 csv 文件中。Get-vmhost 命令没有时间戳输出,我尝试执行 timestamp=(get-date),但是当我尝试使用管道时,它给了我一个错误。有什么想法可以在该 csv 文件中插入带有值的时间戳列吗?
if ( (Get-PSSnapin -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSsnapin VMware.VimAutomation.Core
}
$Server="dc1-vc.example.com"
Connect-VIServer -server $Server -User <id> -Password <pass>
$Timestamp=(get-date)
Get-VMHost | Where-Object {$_.PowerState -eq "PoweredOn"} | Select-Object Timestamp, Name, NumCpu, CpuUsageMhz, CpuTotalMhz, MemoryUsageGB, MemoryTotalGB |
ConvertTo-Csv -NoTypeInformation |Out-File -Append -Encoding ascii -FilePath "c:\output\new_dc1.csv"
Disconnect-VIServer -Server $Server -Confirm:$false
错误:
The term 'Timestamp=' is not recognized as the name of a cmdlet, function, scri
pt file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.