Я не очень хорош в названии вещей, во-первых, извиняюсь, если название немного случайное.
Я создаю сценарий Powershell GUI для легкого создания пользователей Active Directory, однако, когда я отправляю его, он делаетне создавать учетную запись.
Я попытался переопределить переменные и переписать фактический сценарий создания пользователя.
Я не включил все местоположения, поскольку это сделало бы код еще длиннее, однако ниже приведенвсе соответствующие коды.
Надеюсь, вы гений 'может помочь!
Function Display-UserCreation {
$PasswordValue = "Annodata" + [system.web.security.membership]::GeneratePassword(9, 2)
$Password = ConvertTo-SecureString $PasswordValue -AsPlainText -Force
$DisplayName = $UCFirstNameParam + " " + $UCsurNameParam
$Mail = $UCFirstNameParam + "." + $UCsurNameParam + "@" + "annodata.co.uk"
$MailAlias = $UCFirstNameParam + "." + $UCsurNameParam + "@" + $DNSRoot2
$SInitial = $UCsurNameParam[0]
$Initial = $UCFirstNameParam[0]
$SAMAccountName = $UCFirstNameParam + "." + $UCsurNameParam
$SAMAccountLower = $SAMAccountName.ToLower()
$UserPrincipalName = $UCFirstNameParam + "." + $UCsurNameParam
$defaultname = $SAMAccountName
$email = $UCFirstNameParam + "." + $UCsurNameParam
$i = 1
While ((Get-ADUser -Filter "SamAccountName -eq '$SAMAccountName'" -ErrorAction SilentlyContinue) -ne $null) {
$SamAccountName = $defaultname + [string]$i
$Mail = $email + [string]$i + "@" + "annodata.co.uk"
$i++
}
if ( $UCLocationParam -EQ 'Bracknell' ) {
$NewUserParams = @{
path = "OU=Bracknell,OU=Sites,DC=annodata,DC=co,DC=uk"
SamAccountName = $SAMAccountName
Name = $SAMAccountName
DisplayName = $DisplayName
GivenName = $UCFirstNameParam
Surname = $UCsurNameParam
EmailAddress = $Mail
UserPrincipalName = "$SAMAccountName@annodata.co.uk"
Description = $UCRoleParam
ChangePasswordAtLogon = $true
PasswordNeverExpires = $false
AccountPassword = $password
Enabled = $true
}
New-ADUser @NewUserParams -ErrorAction SilentlyContinue
Set-ADAccountPassword -Identity $SAMAccountName -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $Password -Force)
}
}
Function UCSubmit {
if ([System.Windows.Forms.MessageBox]::Show("Please Confirm That The Details Are Correct. If they are, click ok", "Confirmation", [System.Windows.Forms.MessageBoxButtons]::OkCancel) -eq "Ok") {
$UCFirstNameParamLong = New-Object System.Windows.Forms.Label
$UCFirstNameParamLong.Text = $UCFirstName.Text
$UCFirstNameParamLong.Location = New-Object System.Drawing.Point(180, 100)
$UCFirstNameParamLong.AutoSize = $true
$UCFirstNameParamLong.Font = 'Georgia,10'
$UCSurnameParamLong = New-Object System.Windows.Forms.Label
$UCSurnameParamLong.Text = $UCSurname.Text
$UCSurnameParamLong.Location = New-Object System.Drawing.Point(180, 150)
$UCSurnameParamLong.AutoSize = $true
$UCSurnameParamLong.Font = 'Georgia,10'
$UCRoleParamLong = New-Object System.Windows.Forms.Label
$UCRoleParamLong.Text = $UCRole.Text
$UCRoleParamLong.Location = New-Object System.Drawing.Point(180, 200)
$UCRoleParamLong.AutoSize = $true
$UCRoleParamLong.Font = 'Georgia,10'
$UCLocationParamLong = New-Object System.Windows.Forms.Label
$UCLocationParamLong.Text = $UCSiteSelection.Text
$UCLocationParamLong.Location = New-Object System.Drawing.Point(180, 250)
$UCLocationParamLong.AutoSize = $true
$UCLocationParamLong.Font = 'Georgia,10'
$UCFirstNameParam = $UCFirstNameParamLong.Text
$UCSurnameParam = $UCSurnameParamLong.Text
$UCRoleParam = $UCRoleParamLong.Text
$UCLocationParam = $UCLocationParamLong.Text
Display-UserCreation
}
}