Created
May 24, 2017 11:58
-
-
Save Jackbennett/3fc155773f96e909d1554a35f0a245ee to your computer and use it in GitHub Desktop.
A waste of 10 minutes. Know what you're doing with try/catch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# By adding a credential parameter to my function I broke it and couldn't spot the fault for 10 mintues | |
# Rookie Mistake. Beware poor try/catch use. | |
try { | |
# Grab the events from a remote computer | |
$EventLog = Get-WinEvent -ComputerName $ComputerName -FilterHashtable -Credential:$Credential @{ | |
Logname = 'Security'; | |
Id = 4624; | |
StartTime = $StartDay.toShortDateString(); | |
EndTime = $StopDay.toShortDateString(); | |
} -ErrorAction Stop | |
} catch { | |
switch ($ComputerName) | |
{ | |
'localhost' { Write-Error "Must run as an Administrator to acces logs for $ComputerName" } | |
Default { Write-Error "$ComputerName cannot be found" } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment