Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Out-File for loop help

$
0
0

How can I use Out-File for something like this bit

 

$Computers = Get-Content -Path c:\computer.txt

foreach ($Computer in $computers)
{
    Get-Service -DisplayName "*Spooler*" -computer $Computer | select MachineName,DisplayName,Status | Format-List
}

 

If I add | Out-File C:\whatever.txt to the end of the Get-Service command it will only leave me with the last server on the list. If I use the -append command it will also just add to the file.

 

Is there an easy way to take all the results first and then output them to a file? Basically I want it to overwrite the .txt every time it runs instead of using -append...

 

Hope that makes sense and thanks in advance.


Viewing all articles
Browse latest Browse all 6937

Trending Articles