Powershell(以及一般腳本)的新手。 這讓我瘋狂。Powershell函數參數不起作用
試圖創建一個功能腳本在Active Directory中的一些管理工作,我在第一關墮落......在PowerShell中
Function Trainee-Admin {
param($groups = import-csv C:\Users\administrator\Desktop\Powershell\Scripts\TraineeAdmin\groups.csv)
$groups
}
Trainee-Admin
運行時
$groups = import-csv C:\Users\administrator\Desktop\Powershell\Scripts\TraineeAdmin\groups.csv
上面的代碼工作得很好
函數參數中的相同命令不起作用。 我只是得到這個錯誤:
'='後缺少表達式。 在C:\用戶\管理員\桌面\ Powershell的\腳本\ TraineeAdmin \ TraineeAdmin.p S1:3字符:14 + $組= < < < <進口-CSV C:\用戶\管理員\桌面\ Powershell的\以股代息 TS \ TraineeAdmin \ groups.csv + CategoryInfo:ParserError:(=:字符串)[],ParentContainsErrorRec ordException + FullyQualifiedErrorId:MissingExpressionAfterToken
我猜我失去了一些東西很簡單,任何幫助將不勝感激。
感謝guiwhatsthat, – Zeruko
沒問題,請把它標記爲一個答案,當你解決問題了。 – guiwhatsthat
我正在使用函數的參數部分來聲明要在函數中使用的變量。 我忘記了參數部分是用來從字面上爲函數本身創建參數來使用的。 就像我說的 - 總新手。 – Zeruko