在其他域中创建AD用户

时间:2020-02-26 10:02:09

标签: powershell active-directory

我创建了一系列用于创建域用户的脚本。由于我们创建用户的每个域都需要不同的参数和条件,因此每个域都有一个脚本。但是在一个域的情况下,我有一个问题。对于此域,手动过程如下:

1)打开dsa.msc

2)连接到“ xyz”域(正在从“ abc”域中的服务器创建用户)

3)创建用户(操作10到15分钟,这就是我创建脚本的原因)

不幸的是,当我运行脚本时,收到错误消息,即在执行New-ADUser cmdlet时出现“服务器不愿意处理请求”(精确的完整错误消息)。我认为原因是需要执行上述过程中的步骤2。因此,我需要在脚本中对其进行仿真,但是我不知道该怎么做。

这是命令的定义方式:

$params = @{
        'GivenName'             = $First_name_val.Text
        'Surname'               = $Second_name_val.Text
        'DisplayName'           = $Display_name
        'AccountPassword'       = $password
        'Path'                  = $Location_val.Text
        'Name'                  = $User_name_val.Text
        'CannotChangePassword'  = $Cannot_chg_pass.Checked
        'PasswordNeverExpires'  = $Pass_not_expires.Checked
        'ChangePasswordAtLogon' = $Must_chg_pass.Checked
        'Enabled'               = !($Account_disabled_val.Checked)
        'Description'           = $GECOS_val.Text
        'Office'                = "NA"
        'OfficePhone'           = "NA"
        'Title'                 = $Job_Title_val.Text
        'Department'            = $Department_val.Text
        'Company'               = $Company_val.Text
        'SamAccountName'        = $User_name_val.Text
        'UserPrincipalName'     = $User_name_val.Text + "@woodplc.com"
        'EmailAddress'          = $Email_Address_val.Text
        'PassThru'              = $true
    }
    $New_user = New-ADUser @params

$User_name_val.Text的定义在这里:

#region Real name of the user
[void]$AD_user_creation.SuspendLayout()

$Display_name_lbl                = New-Object system.Windows.Forms.Label
$Display_name_lbl.text           = "User`'s real name"
$Display_name_lbl.AutoSize       = $true
$Display_name_lbl.width          = 25
$Display_name_lbl.height         = 10
$Display_name_lbl.location       = New-Object System.Drawing.Point(10,10)

$First_name_val                  = New-Object system.Windows.Forms.TextBox
$First_name_val.Text             = "a."
$First_name_val.multiline        = $false
$First_name_val.width            = 120
$First_name_val.height           = 20
$First_name_val.location         = New-Object System.Drawing.Point(200,10)

$Second_name_val                 = New-Object system.Windows.Forms.TextBox
$Second_name_val.multiline       = $false
$Second_name_val.width           = 120
$Second_name_val.height          = 20
$Second_name_val.location        = New-Object System.Drawing.Point(330,10)

$Display_name_val                = New-Object system.Windows.Forms.Label
$Display_name_val.Text           = ""
$Display_name_val.width          = 250
$Display_name_val.height         = 20
$Display_name_val.location       = New-Object System.Drawing.Point(200,40)

$showFullName = { $Display_name_val.Text = ($First_name_val.Text + "." + $Second_name_val.Text) }

[void]$Second_name_val.Add_Leave( { & $showFullName } )
[void]$First_name_val.Add_Leave(  { & $showFullName } )
#endregion

#region User name of the user
$User_name_lbl                   = New-Object system.Windows.Forms.Label
$User_name_lbl.text              = "User logon name"
$User_name_lbl.AutoSize          = $true
$User_name_lbl.width             = 25
$User_name_lbl.height            = 10
$User_name_lbl.location          = New-Object System.Drawing.Point(10,70)

$User_name_val                   = New-Object system.Windows.Forms.TextBox
$User_name_val.multiline         = $false
$User_name_val.width             = 250
$User_name_val.height            = 20
$User_name_val.location          = New-Object System.Drawing.Point(200,70)
$LogonName = {$User_name_val.Text = ($First_name_val.Text + "." + $Second_name_val.Text)}

[void]$Second_name_val.Add_Leave({& $LogonName})
[void]$First_name_val.Add_Leave({& $LogonName})
[void]$AD_user_creation.ResumeLayout()
#endregion

1 个答案:

答案 0 :(得分:0)

错误"The server is unwilling to process the request"表示您的某些输入值无效。例如,您提供的OU可能无效(可能不应该有空格),或者SamAccountName可能太长或包含无效字符,等等。

如果显示正在使用的完整命令,我也许可以发现一些东西。

如果连接到服务器或进行身份验证时出现问题,则错误消息将有所不同。