使用多个输入提示创建AD用户

时间:2016-04-13 14:01:55

标签: powershell

我想通过逐个询问用户输入的提示来创建AD用户。 我从谷歌搜索脚本。见下文。

    $title = "Login"
$message = "Please enter your information to login!"
$name = New-Object System.Management.Automation.Host.FieldDescription "Name"
$name.Label = "&Login Name"
$name.DefaultValue = "Guest"
$pwd = New-Object System.Management.Automation.Host.FieldDescription "Password"
$pwd.Label = "&Password"
$pwd.SetparameterType( [System.Security.SecureString] )
$pwd.HelpMessage = "Please type your Password."
$fields = [System.Management.Automation.Host.FieldDescription[]]($name, $pwd)
$login=$Host.UI.Prompt($title, $message, $fields)

如何在旧语句

中传递这些参数
New-ADUser -Name “Charlie Russel” `
           -AccountPassword "testing"  `
           -SamAccountName 'Charlie’ `
           -DisplayName 'Charlie Russel’ `
           -EmailAddress 'Charlie@TreyResearch.net’ `
           -Enabled $True `
           -GivenName 'Charlie’ `
           -PassThru `
           -PasswordNeverExpires $True `
           -Surname 'Russel’ `
           -UserPrincipalName 'Charlie’

1 个答案:

答案 0 :(得分:0)

您可以使用$login.Name$login.Password

访问它
New-ADUser -Name 'Charlie Russel' `
           -AccountPassword $login.Password  `
           -SamAccountName $login.Name `
           -DisplayName 'Charlie Russel’ `
           -EmailAddress 'Charlie@TreyResearch.net’ `
           -Enabled $True `
           -GivenName 'Charlie’ `
           -PassThru `
           -PasswordNeverExpires $True `
           -Surname 'Russel’ `
           -UserPrincipalName 'Charlie'