我是PowerShell新手,正在創建一個小腳本,用於從文本文件中導入筆記本電腦和工作站列表,查看它們是否在我們的網絡上並繼續檢查計算機的代理狀態/配置。If Else Statement with String,導出爲CSV
如果電腦不在線,我想有一個文件說$工作站不在線。
我遇到的問題是使用其他數據將該失敗字符串獲取到一個CSV,我可以單獨導出IF和Else,但如果可能的話,最好在一個CSV上使用它。
有什麼想法?謝謝!
$workstation=Get-content C:\Scripts\workstation.txt
$forloop=ForEach ($workstation in $workstation) {
if (Test-Connection -ComputerName $workstation -Count 1 -Quiet) {Get-Service -ComputerName $workstation | where-object {$_.Name -eq 'xxx Agent'} | select displayname, name, starttype, status |
export-csv -Path C:\Scripts\therealdeal.c }
Else {Write-Output "$workstation not available Out"}
}
$forloop | Out-File C:\scripts\output.csv
嘗試更改爲複數以避免變量混淆可能?> $ workstations = Get-content' then($工作站在$ workstations中)'不是100%,但我理解問題。 –