powershell-3.0 - PowerShell : writing to text file

标签 powershell-3.0

我正在尝试获取已安装打印机的列表,以获取计算机列表。

当我运行此脚本时,它仅“写入”最后一台计算机的信息。

我对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/

相关文章:

powershell - 从哈希表中删除重复值

powershell-3.0 - Start-Process 系统找不到指定的文件

regex - 如何制作正则表达式以排除带括号的字符串

powershell - Start-Job 将 XML 对象传递给 -ArgumentList 在 Powershell V2 和 V3 中工作方式不同

Powershell here-string 扩展

Powershell 3 : preventing excessive memory usage for webrequest

PowerShell的 '-Version'参数和CLR版本

PowerShell $PSVersionTable

powershell - 从Powershell函数内部的外部命令流输出

powershell - 使用 powershell 对象执行脚本