我正在尝试获取没有防病毒但计算机名称在一行中的计算机列表,有人可以帮忙吗?
ForEach ($COMPUTER in (Get-ADComputer -Filter {OperatingSystem -notLike '*windows xp*' } | Select-Object -ExpandProperty Name))
{if(!(Test-Connection -Cn $computer -BufferSize 16 -Count 1 -ea 0 -quiet))
{write-host "cannot reach $computer" -f red}
else {
try
{
$AntiVirusProduct = Get-WmiObject -Namespace "root\SecurityCenter2" -Class AntiVirusProduct -ComputerName $computer -ErrorAction Stop
}
catch
{
Write-Warning "[ERROR] invalid namespace [$($computer)] : $_"
$noantivirus+=$computer
}
$noantivirus | out-file -Encoding Ascii -append c:\noantivirus.txt}}
答案 0 :(得分:0)
您可以尝试通过 NewLine
加入它们$noantivirus -join [System.Environment]::NewLine | out-file -Encoding Ascii -append c:\noantivirus.txt
如果这不起作用,请尝试使用rn:
$noantivirus -join "`r`n" | out-file -Encoding Ascii -append c:\noantivirus.txt
答案 1 :(得分:0)
我找到了
$noantivirus = Add-Content c:\noantivirus.txt "`n$computer"