我正在尝试获取已安装打印机的列表,以获取计算机列表。
当我运行此脚本时,它仅“写入”最后一台计算机的信息。
我对PS非常陌生,希望能提供一些帮助。
$filePath = "E:\ps\computerswithprinters.txt"
$class = "win32_printer"
$arycomputer = Get-Content "E:\ps\computers.txt"
foreach( $computer in $aryComputer)
{
Write-Host "Retrieving printers from $computer ..."
$wmi = Get-WmiObject -Class $class -computername $computer
format-table -Property name, systemName, shareName -groupby driverName `
-inputobject $wmi -autosize | Out-File -FilePath $filePath
}
先感谢您!
最佳答案
尝试使用Out-File -FilePath $filePath -Append
关于powershell-3.0 - PowerShell : writing to text file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13952230/