Hey Guys,
I am currently building a Powershell GUI that'll execute a New-ADUser script once all fields are completed and verified.
Currently, I am having issues with my New-ADUser script itself.
I send all values from the TextBoxes to Set-Variables.
This is the script I've got:
New-ADUser -Name "$AD_LastName $AD_FirstName" -AccountExpirationDate $null -AccountPassword $AD_PWS -City $AD_City -Company "MAAX" -Country $AD_Country -Department $AD_Department -Description $AD_PCInfo -DisplayName "$AD_LastName $AD_FirstName" -Enabled $true -GivenName "$AD_FirstName" -Office "$AD_Office" -PostalCode "$AD_PostalCode" -SamAccountName "$AD_Username" -State "$AD_State" -StreetAddress "$AD_Street" -Surname "$AD_LastName" -Title "$AD_JobTitle" -UserPrincipalName "$AD_PName" -PasswordNeverExpires $false -Path "$AD_Path"
Variables are set this way:
Set-Variable -Name "AD_Path" -Value "OU=Users,OU=Site,OU=Company,DC=my,DC=domain" -Scope "Global" -PassThru
Upon executing this script, I get:
ERROR: New-ADUser : A value for the attribute was not in the acceptable range of values
ADNewUser.psf (391, 3): ERROR: At Line: 391 char: 3
ERROR: + New-ADUser -Name "$AD_LastName $AD_FirstName" -AccountExp ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : NotSpecified: (CN=Mother Magic...ymaax,DC=domain:String) [New-ADUser], ADException
ERROR: + FullyQualifiedErrorId : A value for the attribute was not in the acceptable range of values,Microsoft.ActiveDirectory.Management.Commands.NewADUser
ERROR:
I've tested every value individually and have narrowed down the issue to the -Path variable.
Should you want an example with values instead of variables:
Import-Module ActiveDirectory
Set-Variable -Name "AD_PW" -Value "Flying.2016!" -Scope "Global" -PassThru
$AD_PWS = ConvertTo-SecureString $AD_PW -AsPlainText -Force
New-ADUser -Name "Mother Magical" -AccountExpirationDate $null -AccountPassword $AD_PWS -City Quebec -Company "Company" -Country "Canada" -Department "Magical Wonders" -Description "Works Like A Pro" -DisplayName "Mother Magical" -Enabled $true -GivenName "Magical" -Office "Quebec" -PostalCode "A0A 0A0" -SamAccountName "MMOT00000000" -State "Canada" -StreetAddress "1000 Rainbow Road" -Surname "Mother" -Title "Joy Clerk" -UserPrincipalName "MMOT00000000@my.domain" -PasswordNeverExpires $false -Path "OU=Users,OU=Site,OU=Company,DC=my,DC=domain"
When trying to run this with Windows PowerShell ISE with full Admin Rights, I get the following message:
New-ADUser : The server is unwilling to process the request
At line:4 char:1
+ New-ADUser -Name "Mother Magical" -AccountExpirationDate $null -AccountPassword ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (CN=Mother Magic...DC=my,DC=domain:String) [New-A
DUser], ADException
+ FullyQualifiedErrorId : The server is unwilling to process the request,Microsoft.Active
Directory.Management.Commands.NewADUser
I've looked on the internet but can't seem to find a working solution.
Where could the issue be?
Thanks in advance
New-ADUser Issue
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: New-ADUser Issue
Don't set variables just use the control values directly.
New-AdUser -Name $textbox1.Text
Controls are variables - that is they are containers for data. You validation routine would enable the add user button after all values needed are entered. Just assign the control values to the parameters of the command.
New-AdUser -Name $textbox1.Text
Controls are variables - that is they are containers for data. You validation routine would enable the add user button after all values needed are entered. Just assign the control values to the parameters of the command.