【发布时间】:2017-12-19 21:51:48
【问题描述】:
我正在尝试编写将检查服务器主机名的脚本。 现在我有:
计算机.txt
192.168.10.10
192.168.10.11
192.168.10.12
和脚本:
$servers = get-content "C:\Script\computers.txt"
Invoke-Command -Credential company\admin1 -ComputerName $computers -scriptblock {[Environment]::GetEnvironmentVariable("ComputerName")} | out-file C:\Script\report_hostnames.txt
我有报告:
Computer1
Computer2
Computer3
您能帮我添加要报告的 IP 地址和错误状态吗,如下所示:
192.168.10.10 Computer1
192.168.10.11 Computer1
192.168.10.12 Computer Unavailable
我试过:foreach; try、catch 和 if,else 但不明白如何正确使用它。
【问题讨论】:
标签: powershell ip report hostname