Csv 无法通过使用Shellscript ping获取远程服务器的详细信息
无法通过ping服务器获取远程服务器详细信息:Csv 无法通过使用Shellscript ping获取远程服务器的详细信息,csv,powershell,powershell-3.0,powershell-remoting,Csv,Powershell,Powershell 3.0,Powershell Remoting,无法通过ping服务器获取远程服务器详细信息: $servers = Get-Content C:\Users\list.txt $collection = $() foreach ($server in $servers) { $status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s); "NSLookUp" = (nslookup -a $server) }; if (Test-Connection $server -
$servers = Get-Content C:\Users\list.txt
$collection = $()
foreach ($server in $servers)
{
$status = @{ "ServerName" = $server; "TimeStamp" = (Get-Date -f s); "NSLookUp" = (nslookup -a $server) };
if (Test-Connection $server -Count 1 -ea 0 -Quiet)
{
$status["Results"] = "Up"
}
else
{
$status["Results"] = "Down"
}
New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
$collection += $serverStatus
}
$collection | Export-Csv C:\Users\status.csv -NoTypeInformation
无法从此获取远程服务器详细信息“NSLookUp”=(NSLookUp-a$server)
任何建议。。。。。。。伙计们我尝试了你的脚本,用gridview替代了export csv,它成功了。我确实看到了由于-a参数而导致的nslookup错误,但它仍然有效。您配置的DNS服务器可能不知道您的主机 这是使用FT的输出。我只是在这里显示NSLookup属性,否则很难读取
$collection|ft -auto
NSLookUp
--------
{Server: google-public-dns-a.google.com, Address: 8.8.8.8, , Name: google.com...}
{Server: google-public-dns-a.google.com, Address: 8.8.8.8, , Name: ibm.com...}
顺便说一句,我用的是PS3.0
编辑:当我使用导出csv时,我确实看到system.object[]
我想我看到了问题所在。.NSLookup成员是一个行数组。您需要将其转换为单个字符串。比如:
$last = $collection.count -1
0..$last | % {$collection[$_].nslookup = -join $collection[$_].nslookup
更改:
$collection=$()
到$collection=@()
更改:
New-Object -TypeName PSObject -Property $status -OutVariable serverStatus
$collection += $serverStatus
到
nslookup-a$server
做什么…它是否在命令提示符下运行?
当元素是数组而不是字符串时,您将在输出中获得system.object[.我尝试了您的脚本,将gridview替换为export csv,结果成功了。我确实看到了由于-a参数而导致的nslookup错误,但它仍然有效。您配置的DNS服务器可能不知道您的主机。您是否获得远程服务器地址的详细信息,实际上我得到的结果是:“System.Object[]”。我将添加我得到的答案。注释没有必要的格式控制
$collection += New-Object -TypeName PSObject -Property $status