It seems like the built-in Get-EventLog
was overridden by a different function with the same name. Not only is it missing many of its standard parameters, but the command Get-Command Get-EventLog
did not mention Microsoft.Powershell.Management
like it should have:
PS > Get-Command Get-EventLog
CommandType Name ModuleName
----------- ---- ----------
Cmdlet Get-EventLog Microsoft.PowerShell.Management
PS >
You can use New-Alias
to set the name back to the original cmdlet:
$currentDate = get-date
$pastDate = $currentDate.addhours(-5)
#####################################################################
New-Alias Get-EventLog Microsoft.PowerShell.Management\Get-EventLog
#####################################################################
$errorCommand = get-eventlog -Before $currentDate -After $pastDate -logname Application -source "ESENT"
$errorInfo = $errorCommand | out-stringApplication -source "ESENT"
See a demonstration below:
PS > function Get-EventLog { 'Different' }
PS > Get-EventLog # This is a new function, not the original cmdlet
Different
PS > New-Alias Get-EventLog Microsoft.PowerShell.Management\Get-EventLog
PS > Get-EventLog # This is the original cmdlet
cmdlet Get-EventLog at command pipeline position 1
Supply values for the following parameters:
LogName:
Although it might be better to investigate why the cmdlet was overridden in the first place and then fix that instead.