locked
Parse info to different sheet in CSV RRS feed

  • Question

  • We recently had some network health issues where we had to force a GPUPDATE on around 250 computers. I've got the lists of computers and want to use Get-Eventlog to get errors pertaining to domain health into a CSV that I can give it to my domain admins. I have a script that will create an array of computers and write the errors I'm looking for to a CSV but in its present state it creates a CSV for each computer. Is there anyway to change it so that it would just create a new sheet in a single CSV with the log file entries?
    $name = gc env:computername
    $computers = get-content computers.txt
    $dateAfter = "4/12/2017"
    $dateBefore = "4/15/2017"
    $csvfile = "$name.csv"
    Foreach ($computer in $computers)
    {
    if (Test-Connection -ComputerName $Computer -Count 1 -Quiet)
    {
    Get-EventLog -computer $computers -logname System -After $dateAfter -Before $dateBefore | 
    where{$_.EventID -eq 1055 -or $_.EventID -eq 5719} | Format-Table -auto -wrap | out-file -filepath $csvfile}
    } 

    Friday, September 29, 2017 3:52 PM

Answers

  • The script you have posted does not create a CSV.  It creates a text file with a CSV extension.

    Remove Format-Table and place Export-Csv command outside of loop.

    Ask the person who wrote the script for help.  We do not use Get-Eventlog on system post-Vista.  The script you have posted will take almost forever to run against many computers.

    help get-winevent -full


    \_(ツ)_/

    Friday, September 29, 2017 5:57 PM