似乎内置Get-EventLog
函数被具有相同名称的不同函数覆盖。它不仅缺少许多标准参数,而且该命令Get-Command Get-EventLog
没有提及Microsoft.Powershell.Management
它应该具有的内容:
PS > Get-Command Get-EventLog
CommandType Name ModuleName
----------- ---- ----------
Cmdlet Get-EventLog Microsoft.PowerShell.Management
PS >
您可以使用New-Alias
将名称设置回原始 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"
请看下面的演示:
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:
尽管最好先调查一下为什么cmdlet 会被覆盖,然后再修复它。