【发布时间】:2015-06-12 03:46:59
【问题描述】:
我有一大串主机名,我需要 ping 以查看它们是启动还是关闭。我不是很擅长编写脚本,但我设法弄清楚了这一点:
$names = Get-content "hnames.txt"
foreach ($name in $names){
if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
Write-Host "$name is up" -ForegroundColor Green
}
else{
Write-Host "$name is down" -ForegroundColor Red
}
}
这得到了我需要的东西,但我现在需要将这些结果写到一个 csv 文件中,我不知道该怎么做。
请帮忙!
【问题讨论】:
标签: loops powershell csv ping