2016-08-22 52 views
2

我試圖獲取沒有防病毒但出文件與計算機名稱單行的計算機的列表,任何人都可以幫忙嗎?向Out-File cmdlet添加換行符

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

我發現它

$noantivirus = Add-Content c:\noantivirus.txt "`n$computer" 
0

您可以嘗試通過換行符加入他們的行列:

$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 
+0

不算其製作的三角形le,矩形 – DisplayName