I am writing a Powershell cmd to:
1) read list of machines stored in a txt file
2) export each machine's 'applciation', 'error' from event viewer
3) save as <computername>.csv
4) read next machine name and so on... 
This is the cmd I use to output the remote event viewer for 1 machine (this works):
Get-EventLog application -computername MACHINE1| where{$_.entrytype -eq"Error"} | Format-Table -auto -wrap | out-file -filepath c:\eventvwr1.txt
I am having trouble getting it to work with multiple machines.
I have created a txt file c:\machines_List.txt which contains machine names.
This is what I have tried:
Get-Content c:\machines_List.txt | Foreach-Object {Get-EventLog application -computername ????| where{$_.entrytype -eq"Error"} | Format-Table -auto -wrap | out-file -filepath c:\?????.csv}
This doesn't work. I'm not sure what to put after -computername and ???.csv. Not even sure it would work anyhow.
Also, in my txt file which contains the machine names, how should I list them? A machine name per line or seperated with comma etc?
Any advice would be very much appreciated.
0 Comments   [ + ] Show Comments


Please log in to comment

Community Chosen Answer


Give this a shot. This will output the file to c:\temp\computername.csv. I would assume that you would want these somewhere on a share somewhere? If that is the case change "$csvfile = "c:\temp\$computer.csv" to $csvfile = "\\share_name\temp\$computer.csv"

$computer= gc env:computername

$file= "c:\temp\computer.txt"

$csvfile = "c:\temp\$computer.csv"

Get-Content $file | Foreach-Object {Get-EventLog application| where{$_.entrytype -eq"Error"} | Format-Table -auto -wrap | out-file -filepath $csvfile}
Answered 09/12/2012 by: dugullett
Red Belt

  • or something like this.

    $name= gc env:computername
    $computers= get-content c:\temp\computer.txt
    $csvfile = "c:\temp\$name.csv"
    foreach ($computer in $computers) {Get-EventLog -computer $computers -logname application |
    where{$_.entrytype -eq"Error"} | Format-Table -auto -wrap | out-file -filepath $csvfile}

    Also you don't want any separators. You can just list them.

Please log in to comment



Thanks very much for taking time to reply. Very much appreciated.

New to Powershell so trying to find the easiest way to get it to run on a system ( save as PS1, signing it etc). One of the machines I will be running it from has Powershell 1 and the other has ver 2.

Never realised it wasn't as simple as dbl clicking a .ps1 file to run it.

Will let you know how I get on.


Answered 09/13/2012 by: Meic
Second Degree Blue Belt

  • Two things that helped me are here. I also suggest snapshotting a VM to run these on. I've broken a few things before.


    Also I'm not sure of your deployment method. Some of my scripts I've created exe's for. Take a look at this link for more details.
Please log in to comment
Answer this question or Comment on this question for clarity