IT Guy
asked on
Error while running Server 2016 Power Shell command
I am trying to follow the instructions within the the https://social.technet.microsoft.com/wiki/contents/articles/24541.powershell-bulk-create-ad-users-from-csv-file.aspx#Code_Used webpage to import username information from a .CSV file to create usernames within Server 2016 Active Directory but every time I try to do this I receive the following error messages:
When I run the following command within PowerShell (running as an administrator) .\un.ps1 I get the error message
“ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:12 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .PowerShel l.Commands .ConvertTo SecureStri ngCommand
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:12 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .PowerShel l.Commands .ConvertTo SecureStri ngCommand” which displays for every username that I attempt to create (see the screenshot).
I have included the CSV spreadsheet I am using with this command.
What needs to be done to fix this so I will be able to successfully import the information to create these usernames within Server 2016 Active Directory?
Here is a screenshot of these error messages:
I receive these errors when running the .\un.ps1 command from an elevated PowerShell
Here is a screenshot of the CSV file:
UN.csv
In this case the CSV file is saved in the "File format is CSV UTF-8 Comma delimited" format. Is this the correct format to save the file in?
The context of the UN.ps1 PowerShell command is:
What needs to be done to fix this so I will be able to successfully import & create these Server 2016 Active Directory users using this power shell command and the CSV file?
Please let me know if any further information is needed.
When I run the following command within PowerShell (running as an administrator) .\un.ps1 I get the error message
“ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:12 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:12 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
I have included the CSV spreadsheet I am using with this command.
What needs to be done to fix this so I will be able to successfully import the information to create these usernames within Server 2016 Active Directory?
Here is a screenshot of these error messages:
I receive these errors when running the .\un.ps1 command from an elevated PowerShell
Here is a screenshot of the CSV file:
UN.csv
In this case the CSV file is saved in the "File format is CSV UTF-8 Comma delimited" format. Is this the correct format to save the file in?
The context of the UN.ps1 PowerShell command is:
$Users = Import-Csv -Path "C:\support\un\CompanyUN.csv"
foreach ($User in $Users)
{
$Displayname = $User.Firstname + " " + $User.Lastname
$UserFirstname = $User.Firstname
$UserLastname = $User.Lastname
$OU = "$User.OU"
$SAM = $User.SAM
$UPN = $User.Firstname + "." + $User.Lastname + "@" + $User.Maildomain
$Description = $User.Description
$Password = $User.Password
New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamAccountName $SAM -UserPrincipalName $UPN -GivenName "$UserFirstname" -Surname "$UserLastname" -Description "$Description" -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Enabled $true -Path "$OU" -ChangePasswordAtLogon $false –PasswordNeverExpires $true -server domain.loc
}
What needs to be done to fix this so I will be able to successfully import & create these Server 2016 Active Directory users using this power shell command and the CSV file?
Please let me know if any further information is needed.
Please check with the second version of the code from the same page.
ASKER
Nagendra Pratap Singh,
I have used the second version of the code on the same page and now I receive the following errors:
PS C:\Support\UN> .\un.ps1
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:13 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .PowerShel l.Commands .ConvertTo Se
cureStringCommand
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:13 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .PowerShel l.Commands .ConvertTo Se
cureStringCommand
Here is the screenshot:
I have used the second version of the code on the same page and now I receive the following errors:
PS C:\Support\UN> .\un.ps1
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:13 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
cureStringCommand
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At C:\Support\UN\UN.ps1:13 char:232
+ ... scription" -AccountPassword (ConvertTo-SecureString $Password -AsPlai ...
+ ~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
cureStringCommand
Here is the screenshot:
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
footech,
I have added these headers to the .CSV file.
Now whenI run the .PS1 powershell command I get the following error message:
PS C:\Support\UN> .\un.ps1
New-ADUser : Unable to contact the server. This may be because this server does not exist, it is currently down, or it
does not have the Active Directory Web Services running.
At C:\Support\UN\UN.ps1:13 char:5
+ New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-ADUser], ADServerDownException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Mi crosoft.Ac tiveDirect ory.Manage ment.Comma nds.NewADU ser
And here is the spreadsheet with these headers at the top of the spreadsheet
Here is a screenshot of Active Directory Users and Computers for this Server 2016 AD domain
What else needs to be done to fix this latest error?
I have added these headers to the .CSV file.
Now whenI run the .PS1 powershell command I get the following error message:
PS C:\Support\UN> .\un.ps1
New-ADUser : Unable to contact the server. This may be because this server does not exist, it is currently down, or it
does not have the Active Directory Web Services running.
At C:\Support\UN\UN.ps1:13 char:5
+ New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceUnavailable: (:) [New-ADUser], ADServerDownException
+ FullyQualifiedErrorId : ActiveDirectoryServer:0,Mi
And here is the spreadsheet with these headers at the top of the spreadsheet
Here is a screenshot of Active Directory Users and Computers for this Server 2016 AD domain
What else needs to be done to fix this latest error?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The parameter is "-asPlain" check that
Here's a similar question I think this question will clarify your doubt.
https://www.experts-exchan ge.com/que stions/290 48293/I-ne ed-to-add- user-by-cs v-file-to- AD-with-Po werShell.h tml
Here's a similar question I think this question will clarify your doubt.
https://www.experts-exchan
ASKER
J0rt3g4,
Are you saying that the -asPlain should be removed? Or should it be modified to something else?
Here are screenshots of the PowerShell script
Continuation of PowerShell script
P.S. I have renamed the .CSV file name to CompanyUN.csv
Also now when I run the Power Shell script I get these errors:
PS C:\Support\UN> .\un.ps1
New-ADUser : Directory object not found
At C:\Support\UN\UN.ps1:13 char:5
+ New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (CN=Accounts Pay...=a______,DC=com:Stri ng) [New-ADUser], ADIdentityNotFo
undException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Micr osoft.Acti veDirector y.Manageme nt.ADIdent ityNotFoun dException ,M
icrosoft.ActiveDirectory.M anagement. Commands.N ewADUser
New-ADUser : Directory object not found
At C:\Support\UN\UN.ps1:13 char:5
+ New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (CN=Al________...=a_____,D C=com:Stri ng) [New-ADUser], ADIdentityNotFo
undException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Micr osoft.Acti veDirector y.Manageme nt.ADIdent ityNotFoun dException ,M
icrosoft.ActiveDirectory.M anagement. Commands.N ewADUser
[PLEASE NOTE: Usernames and Domain names have been blanked out]
[PLEASE NOTE: Usernames and Domain names have been blanked out]
Here is a screenshot of the CSV file. Am I using the correct header names? Also should the OU simply be OU=users,DC=companyname,DC =com
Here is a screenshot of our Active Directory users and computers. Is the OU context of "OU=users,DC=companyname,D C=com" correct?
Please let me know if any further information is needed.
Are you saying that the -asPlain should be removed? Or should it be modified to something else?
Here are screenshots of the PowerShell script
Continuation of PowerShell script
P.S. I have renamed the .CSV file name to CompanyUN.csv
Also now when I run the Power Shell script I get these errors:
PS C:\Support\UN> .\un.ps1
New-ADUser : Directory object not found
At C:\Support\UN\UN.ps1:13 char:5
+ New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (CN=Accounts Pay...=a______,DC=com:Stri
undException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Micr
icrosoft.ActiveDirectory.M
New-ADUser : Directory object not found
At C:\Support\UN\UN.ps1:13 char:5
+ New-ADUser -Name "$Displayname" -DisplayName "$Displayname" -SamA ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (CN=Al________...=a_____,D
undException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Micr
icrosoft.ActiveDirectory.M
[PLEASE NOTE: Usernames and Domain names have been blanked out]
[PLEASE NOTE: Usernames and Domain names have been blanked out]
Here is a screenshot of the CSV file. Am I using the correct header names? Also should the OU simply be OU=users,DC=companyname,DC
Here is a screenshot of our Active Directory users and computers. Is the OU context of "OU=users,DC=companyname,D
Please let me know if any further information is needed.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
footech,
Thank you very much for your help!
I followed the instructions in your last comment, ran the PowerShell script again, and now all of the AD accounts have been created.
Thank you very much for your help!
I followed the instructions in your last comment, ran the PowerShell script again, and now all of the AD accounts have been created.
ASKER