【发布时间】:2020-08-31 17:07:03
【问题描述】:
我正在尝试创建一个基本脚本,该脚本从文本文件中提取计算机名称列表,然后对它们执行 ping 操作,并返回 true 或 false。然后我想将返回 false 的那些输出到一个文本文件,这样我就可以知道哪些没有响应。
最接近我想要的结果如下:
$workstations = Get-Content "workstation_list.txt"
$workstations | Test-NetConnection -InformationLevel Quiet -WarningAction SilentlyContinue
但是,每当我尝试将结果传递到任何地方时,我得到的都是真假。
如何传递 $workstations 数组中的原始名称以显示所有返回 false 的名称?
我试过了:
$workstations = Get-Content "workstation_list.txt"
$workstations |
Test-NetConnection -InformationLevel Detailed -WarningAction SilentlyContinue |
Select-Object computername, pingsucceeded |
if(pingsucceeded -eq False){write-output} else{continue}
出现以下错误:
pingsucceeded : The term 'pingsucceeded' is not recognized as the name of a cmdlet, function, script 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.
At line:11 char:144
+ ... Select-Object computername, pingsucceeded | if(pingsucceeded -eq Fal ...
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (pingsucceeded:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException*
但是我不知道如何只返回在我 ping 时返回 false 的计算机的原始名称。
然后我想将它输出到一个文本文件,但是如果我不能让它将正确的信息传递到屏幕它也不会转到一个文件。
我是接近还是需要以完全不同的方式处理这个问题?
谢谢!
PS.这是我第一次发布有关堆栈溢出的问题,如果我需要以不同的方式提供信息以使您更容易回答,请提供建设性的反馈,以便我将来做得更好。
【问题讨论】:
标签: powershell pipe ping powershell-5.0