目前運行到一個奇怪的錯誤使用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