Powershell Get-EventLog System -After -Before from remote nodes

192 Views Asked by At

I'm trying to get the EventLog systems from a list of nodes; I'm using psexec  and Get-EventLog. I would like to speed up the procedure by adding the After and Before parameters that I would like to read from a file.

This is the piece of code that runs on the server:

#$Da = Pick-Date -testo "DATA INIZIO?"
#$Da | Out-File $localDir\GetEventLog.da.txt
#$Al = Pick-Date -testo "DATA FINE?"
#$Al | Out-File $localDir\GetEventLog.al.txt

foreach ($node in Get-Content $localDir\GetEventLog.input.txt)
{
    net use N: $node\c$ $pwd /user:$node\administrator
    mkdir N:\GetEventLog\
    copy $localDir\GetEventLog.cmd N:\GetEventLog\
    copy $localDir\GetEventLog.ps1 N:\GetEventLog\
# copy $localDir\GetEventLog.da.txt N:\GetEventLog\
# copy $localDir\GetEventLog.al.txt N:\GetEventLog\
    psexec $node C:\GetEventLog\GetEventLog.cmd
    copy N:\GetEventLog\System.* $localDir\
    net use N: /delete
    pause
}

This is the one running on clients:

$wrkDir = "c:\GetEventLog"
$filenameFileOutput = "$wrkDir\System." + $(hostname) + ".txt"
Get-EventLog System | Out-File -Width 200 $filenameFileOutput

I can't pass the contents of the GetEventLog.da.txt and GetEventLog.al.txt files as parameters to Get-EventLog.

Thanks

0

There are 0 best solutions below