When I try to run this script:
$Filename = ""U:\logfile_analysis\raw_data\SavedSecurity.evtx""
$EventIDsLogon.ToString() = "4624"
$EventIDsLogoff.ToString() = "4647"
$EventIDsLogonFailure.ToString() = "4625"
$EventIDsLockScreen.ToString() = "4800"
$EventIDsUnlockScreen.ToString() = "4801"
$EventIDstemp = $EventIDsLogon, $EventIDsLogoff, $EventIDsLogonFailure, $EventIDsLockScreen, $EventIDsUnlockScreen -join ","
$EventIDsSummary = $EventIDstemp.Trim()
#Write-Host $EventIDsSummary
Write-Host "Get-WinEvent -FilterHashtable @{Path='$Filename'; ID=$EventIDsSummary}"
pause
Get-WinEvent -FilterHashtable @{Path='$Filename'; ID=$EventIDsSummary}
and look at the output from
Write-host "Get-WinEvent -FilterHashtable @{Path='$Filename'; ID=$EventIDsSummary}"
the ouput is:
Get-WinEvent -FilterHashtable @{Path='U:\logfile_analysis\raw_data\SavedSecurity.evtx'; ID=4624,4647,4625,4800,4801}
When I copy the output from Write-Host to a PowerShell console it works:
PS> Get-WinEvent -FilterHashtable @{Path='U:\logfile_analysis\raw_data\SavedSecurity.evtx'; ID=4624,4647,4625,4800,4801}
ProviderName: Microsoft-Windows-Security-Auditing
TimeCreated Id LevelDisplayName Message
----------- -- ---------------- -------
04.12.2017 13:56:56 4624 Informationen Ein Konto wurde erfolgreich angemeldet...
04.12.2017 13:56:56 4647 Informationen Benutzerinitiierte Abmeldung:...
04.12.2017 13:56:48 4801 Informationen Die Arbeitsstation wurde entsperrt...
04.12.2017 13:56:48 4624 Informationen Ein Konto wurde erfolgreich angemeldet...
04.12.2017 13:56:48 4624 Informationen Ein Konto wurde erfolgreich angemeldet...
******** truncated ****
But:
Get-WinEvent -FilterHashtable @{Path='$Filename'; ID=$EventIDsSummary}
did not work.
Error Message is:
Get-WinEvent : Cannot find path 'U:\logfile_analysis\$Filename' because it does not exist.
I tried to add "" at @{Path="$Filename"....
I tried to add '' at @Path="$Filename"....
I tried to manipulate the $Filename variable and add"", the variable$Filename` looks like
$Filename = '"U:\logfile_analysis\raw_data\SavedSecurity.evtx"'
$Filename = ""U:\logfile_analysis\raw_data\SavedSecurity.evtx""
$Filename = "'U:\logfile_analysis\raw_data\SavedSecurity.evtx'"
No success.
A deeper look shows the problem, @Path='$Filename'
The path must be within two "", how can I add them that the script works?
$Filename="U:\logfile_analysis\raw_data\SavedSecurity.evtx" ; Get-WinEvent -FilterHashtable @{Path=$Filename; ID=$EventIDsSummary}- Loïc MICHELIDan actual array, not a comma-delimited string:$EventIDsSummary = 4624, 4647, 4625, 4800, 4801. Also,$var.ToString() = "..."can't possibly work and should have given you a "cannot call a method on a null-valued expression" error. - Ansgar WiechersEventIDstemp=@($EventIDsLogon, $EventIDsLogoff, $EventIDsLogonFailure, $EventIDsLockScreen, $EventIDsUnlockScreen -join ",")and runGet-WinEvent -FilterHashtable @{Path=$Filename; ID=$EventsIDstemp}. no idea, why.echo $EventIDstempgives4624,4647,4625,4800,4801, Errormessage isGet-WinEvent : A null value was encountered in the ID hash table key. Null values are not permitted.- Peter Core