Powershell管不工作

时间:2014-04-22 23:41:52

标签: powershell pipe

我想弄清楚为什么这个powershell代码不会将值传递到CSV文件中。我试图从PingStatus结果中获取TimeStamp,Destination等,并将其转换为CSV文件以进行日志记录。这在屏幕(控制台)上工作正常,但是当我尝试将其传输到CSV文件时,我只得到了分隔符","。对于什么是错误的建议或者可能是一个更简单的解决方案?

$Address = "wired.com"
$LogPath = "\\path\PingLog.csv"

$Ping = Get-WmiObject Win32_PingStatus -Filter "Address = '$Address'" | Select @{Label="TimeStamp";Expression={Get-Date}},@{Label="Source";Expression={ $_.__Server }},@{Label="Destination";Expression={ $_.Address }},IPv4Address,@{Label="Status";Expression={ If ($_.StatusCode -ne 0) {"Failed"} Else {"Success"}}},ResponseTime    
$Result = $Ping | Select TimeStamp,Source,Destination,IPv4Address,Status,ResponseTime | ConvertTo-Csv -NoTypeInformation    
$Result[1] | Add-Content -Path $LogPath    
Write-verbose ($Ping | Select TimeStamp,Source,Destination,IPv4Address,Status,ResponseTime | Format-Table -AutoSize | Out-String)

0 个答案:

没有答案