gpt4 book ai didi

powershell - 将换行符添加到Out-File cmdlet

转载 作者:行者123 更新时间:2023-12-03 00:14:29 26 4
gpt4 key购买 nike

我正在尝试获取没有防病毒软件的计算机列表,但是out文件的计算机名称在一行中,有人可以帮忙吗?

    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}}

最佳答案

您可以尝试通过换行加入他们:

$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

关于powershell - 将换行符添加到Out-File cmdlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39085173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com