Hi All,
Am new to PowerShell and still learning my way about.
I am running the following snippet of code ...
$event= Get-EventLog -LogName Security -ComputerName [DCServer] -InstanceId 4740 -Newest 1 |
Select TimeGenerated,ReplacementStrings,"Account name","Account Domain","Caller Computer Name" |
% {
New-Object PSObject -Property @{
"Account name" = $_.ReplacementStrings[-7]
"Account Domain" = $_.ReplacementStrings[5]
"Caller Computer Name" = $_.ReplacementStrings[1]
Date = $_.TimeGenerated
}
}
My question is how should I best handle this when it returns nothing?
Example:
Get-EventLog : No matches found
At line:1 char:1
+ Get-EventLog -LogName Security -ComputerName [DCServer] -InstanceId 4740 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-EventLog], ArgumentException
+ FullyQualifiedErrorId : GetEventLogNoEntriesFound,Microsoft.PowerShell.Commands.GetEventLogCommand
Thanks in advance.
Cheers, Cameron