I am writing a function in powershell to use Get-WinEvent of a remote computer to view Event IDs from a textbox in a form.
The function is:
function getSystemEvents {
$EventCode = $EventInputBox.text;
$CompName = $PCInputBox.Text;
$Network = 'myNetwork.net'
$ListEvent = Invoke-Command -ComputerName $CompName$Network -ScriptBlock {Get-WinEvent -FilterHashtable @{logname='system'; id=$EventCode} | Select-Object TimeCreated, ID, Message | ft -auto} | out-string
$outputBox.text=$ListEvent
}
The id=$EventCode does not work. If I manually replace it with id='12' instead of the variable, I will get a list of EventID=12s from the remote machine.
I think possibly the issue is that I don't know how to put the variable $EventCode in between two ' characters like id='$EventCode' without breaking the script.
Many thanks in advance!