Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell : writing to text file

I am trying to get a list installed printers for a list of computer.

When I run this script, it only "writes" the last computer's information.

I am VERY new to PS and would appreciate some help.

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

Thank you in advance!

like image 402
Khan Avatar asked Dec 19 '12 12:12

Khan


1 Answers

Try using Out-File -FilePath $filePath -Append

like image 62
kb_sou Avatar answered Jan 01 '23 11:01

kb_sou