目前运行到一个奇怪的错误使用PowerShell的函数PowerShell脚本递归错误
下面的代码:
import-module ActiveDirectory
function Reset-Passwords{
#Imports csv containing user details. The column names indicate the property type of the values in each row.
$users = import-CSV -path "C:\Users\administrator\Desktop\Powershell\Scripts\NQSMoves\NQS\NQSDetails.csv"
$SamAccountNames = $Users | select sAMAccountName
$password = Convertto-SecureString -string "228Hamilton" -asPlainText -force
foreach($SamAccountName in $SamAccountName){
set-adAccountPassword -identity $SamAccountName -reset -newPassword $password
}
}
Reset-Passwords
运行时,它输出的错误:
The script failed due to call depth overflow. The call depth reached 1001 and the maximum is 1000.
从我已经收集到,这是一个递归错误。
但是,只有26'$ samAccountName'变量,所以foreach循环应该只运行26次? csv文件本身只有26行,所以这应该限制foreach循环。
这只是更大的AD管理脚本的一部分,它是唯一提供问题的部分。
任何帮助将不胜感激。
这是正确的代码,它不应该是 的foreach($ SAM帐户在$ SamAccountNames) – superblygeneralobject
的列出你的迭代不是你认为的那样。这可能会导致这个问题。 –
另外我在代码 – superblygeneralobject