$secPassword = Read-Host "Password" -AsSecureString
New-ADUser
-Name "XYZ ABC"
-SamAccountName xyz.a
-UserPrincipalName "[email protected]"
-AccountPassword $secPassword
-Path "cn=Users,dc=ntsh,dc=local"
-Enabled:$true
-PasswordNeverExpires:$true
-CannotChangePassword:$true
-PasswordNotRequired:$false
-ChangePasswordAtLogon:$false
它為所有引數提供 CommandNotFoundException 錯誤。我的腳本有什么問題?
uj5u.com熱心網友回復:
恕我直言,根據 Zett42 的建議,噴濺是最干凈的編碼方式:
$NADUArgs = @{
Name = "XYZ ABC"
SamAccountName = "xyz.a"
UserPrincipalNam = "[email protected]"
AccountPassword = $secPassword
Path = "cn=Users,dc=ntsh,dc=local"
Enabled = $true
PasswordNeverExpires = $true
CannotChangePassword = $true
PasswordNotRequired = $false
ChangePasswordAtLogon = $false
}
New-ADUser @NADUArgs
uj5u.com熱心網友回復:
最簡單的方法是在單行中使用 CMDLET,因為它將它們視為外來命令,而第二種方法如果您想讓它好奇,則添加符號`以便 cmdlet 檢測到它在下一行繼續
第一種方式:
$secPassword = Read-Host "Password" -AsSecureString
New-ADUser -Name "XYZ ABC" -SamAccountName xyz.a -UserPrincipalName "[email protected]" -AccountPassword $secPassword -Path "cn=Users,dc=ntsh,dc=local" -Enabled:$true -PasswordNeverExpires:$true -CannotChangePassword:$true -PasswordNotRequired:$false -ChangePasswordAtLogon:$false
第二種方式:
$secPassword = Read-Host "Password" -AsSecureString
New-ADUser -Name "XYZ ABC" `
-SamAccountName xyz.a `
-UserPrincipalName "[email protected]" `
-AccountPassword $secPassword `
-Path "cn=Users,dc=ntsh,dc=local" `
-Enabled:$true `
-PasswordNeverExpires:$true `
-CannotChangePassword:$true `
-PasswordNotRequired:$false `
-ChangePasswordAtLogon:$false
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/532927.html
標籤:电源外壳活动目录
上一篇:Powershell初學者腳本
下一篇:如何從純文本輸出中過濾
