I have this snippet of code here:
$currentDate = get-date
$pastDate = $currentDate.addhours(-5)
$errorCommand = get-eventlog -Before $currentDate -After $pastDate -logname Application -source "ESENT"
$errorInfo = $errorCommand | out-string
I have a local machine that I run the entire script on, and it works 100% fine. When I run this code on Windows Server standard, via remote desktop, I get the following:
"Get-EventLog : A parameter cannot be found that matches parameter name 'before'" It refers to "$errorCommand =" and I cannot for the life of me figure out why it cannot find this parameter, is something setup incorrectly with my powershell?
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 commandGet-Command Get-EventLog
did not mentionMicrosoft.Powershell.Management
like it should have:You can use
New-Alias
to set the name back to the original cmdlet:See a demonstration below:
Although it might be better to investigate why the cmdlet was overridden in the first place and then fix that instead.