我这里有一段代码:
$currentDate = get-date
$pastDate = $currentDate.addhours(-5)
$errorCommand = get-eventlog -Before $currentDate -After $pastDate -logname Application -source "ESENT"
$errorInfo = $errorCommand | out-string我有一个本地机器,我运行整个脚本,它工作100%很好。当我在Windows Server标准上通过远程桌面运行此代码时,我得到以下信息:
“Get:找不到一个与参数名‘A’匹配的参数,它引用的是"$errorCommand =”,而我一生都无法弄清楚为什么它找不到这个参数,是不是我的powershell设置不正确?
发布于 2014-06-25 19:01:15
似乎内置的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,然后再修复它。
https://stackoverflow.com/questions/24416171
复制相似问题