我对下面编写的代码有疑问。该代码应该做的是获取预定义用户的列表,然后尝试针对用户帐户测试 3 个密码。 (完整的代码已放在下面的答案中)我不断收到代码中的错误,如标题中所述。任何人都可以帮我解决这个问题吗?我总是来这里寻找答案,因为你们是最棒的!今天我无法弄清楚这一点。
$cred = New-Object -TypeName System.Management.Automation.PSCredential Argumentlist $account, $entry
foreach ($account in $accountfile){
try {
get-aduser “username” -credential $cred
$array += New-Object psobject -property @{'Account'=$account;'Password'=$entry}
}
catch { Write-Host "There was an issue"}
}
}
$count++#increase counter
}
$newpass=$newpass[3..$newpass.count] #subtract the first 3 entries from the $newpass array
$count= 0 #reset counter to zero
最佳答案
您错过了 ArgumentList 上的 -。
$cred = New-Object -TypeName System.Management.Automation.PSCredential -Argumentlist $account, $entry
关于PowerShell-新对象 : A Postional parameter cannot be found that accepts argument 'system.object[]' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32643022/