【发布时间】:2015-06-08 19:05:30
【问题描述】:
简单的脚本,但不知道为什么会出现错误:它应该只将成功的机器写入一个文本文件,而将失败的机器写入另一个。
这是我得到的错误:
表达式或语句中出现意外标记“$ip”。 + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : UnexpectedToken
$computers = Get-Content C:\temp\machines_no_rdp.txt
foreach($computer in $computers)
{
if((New-Object System.Net.NetworkInformation.Ping).Send("$computer",[int]1000).Address.IPAddressToString)
{
$computer
$ip = [System.Net.Dns]::GetHostByName($computer).AddressList.IPAddressToString
$computer + ";" $ip | Out-File C:\temp\Success.txt -Append
}
else{$computer + ";" + "Dead" | Out-File C:\temp\failure.txt -Append}
}
【问题讨论】:
-
这只是一个缺少的
+。$computer + ";" $ip应该是$computer + ";" + $ip或许多其他字符串连接解决方案。 -
再次非常感谢.. @Matt