我运行了本文中找到的Powershell脚本:How to detect applications using "hardcoded" DC name or IP。Powershell脚本错误 - 无法验证参数“属性”上的参数:无法索引到空数组中
Get-WinEvent -ComputerName dc01.contoso.com -MaxEvents 1000 -FilterHashtable @{LogName="Directory Service" ; ID=1139 } | ForEach-Object `
{
$_info = @{
"Operation" = [string] $_.Properties.Value[0]
"User" = [string] $_.Properties.Value[2]
"IP:Port" = [string] $_.Properties.Value[3]
}
New-Object psobject -Property $_info
}
我收到的错误是:
New-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
At C:\scripts\HideDC.ps1:9 char:37
+ New-Object psobject -Property <<<< $_info
+ CategoryInfo : InvalidData: (:) [New-Object],
ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.NewObjectCommand
Cannot index into a null array.
At C:\scripts\HideDC.ps1:5 char:55
+ "Operation" = [string] $_.Properties.Value[ <<<< 0]
+ CategoryInfo : InvalidOperation: (0:Int32) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
任何人都可以在这方面帮助?
安置自己的代码有问题:它在指定的位置返回字符。不要使用图片作为代码。 – Fairy
调试代码,在循环内的PowerShell ISE中设置一个断点并检查变量值。 – wOxxOm