Hi I made powershell script in which I am taking three arguements(in param block) and passing them as parameters to -FilterXPath. But I am not able to get the result.
$eventID=7036
$ServiceName=PW
$Status=stopped
It gives me the correct result if I put in the values instead of variables.
Please help. It is very urgent.
param($eventID,$ServiceName,$Status)
$eventID | add-content "path\hello.txt"
$ServiceName | add-content "path\hello.txt"
$Status | add-content "path\hello.txt"
sleep 5
$ErrorTime=Get-WinEvent -LogName 'System' -FilterXPath 'Event[System[EventID=$(eventID)] and EventData[Data[@Name="param1"]="$(ServiceName)" and Data[@Name="param2"]="$(Status)" ]]' -MaxEvents 1 | select -expand timecreated
$ErrorTime | add-content "path\hello.txt"