Store PowerShell script output to a file -
i have created script collect list of users part of remote servers localadmin group , can see output in powershell prompt.
but how can save output file?
any appreciated.
foreach ($computer in get-content c:\server.txt) { echo "$computer" $admins = invoke-command {net localgroup administrators} -computername $computer $results = $computer + " " + $admins | out-file -append c:\adminmember.txt }
change code if want avoid mangled lines:
foreach ($computer in get-content c:\server.txt) { $admins = invoke-command { net localgroup administrators | out-string } -computer $computer "{0}`r`n{1}" -f $computer, $admins | add-content 'c:\adminmember.txt' }
Comments
Post a Comment