Solved

Powershell Scripting Issue

Posted on 2013-06-14
4
1,694 Views
Last Modified: 2013-06-14
Hi - I'm trying to create a powershell script to create new active directory users.  Attached is my CSV file and script.  I'm receiving the following errors:

-DisplayName : The term '-DisplayName' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\emeka\Google Drive\PowerShell\Bulk User Creation\BulkUserCreation.ps1:19 char:6
+                     -DisplayName $DisplayName -EmailAddress $Email -Description $Description`
+                     ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-DisplayName:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
-GivenName : The term '-GivenName' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\emeka\Google Drive\PowerShell\Bulk User Creation\BulkUserCreation.ps1:20 char:6
+                     -GivenName $FirstName -Surname $Surname -PassThru -Enabled $true -Path $OU`
+                     ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-GivenName:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
-AccountPassword : The term '-AccountPassword' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\emeka\Google Drive\PowerShell\Bulk User Creation\BulkUserCreation.ps1:21 char:6
+                     -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -force)`
+                     ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-AccountPassword:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Please assist.
Book3.csv
script.txt
0
Comment
Question by:emeka57
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 40

Accepted Solution

by:
Adam Brown earned 500 total points
ID: 39248610
It looks like you have a carriage return or two in your new-aduser command. Remove those. Each command has to exist on a single line with no carriage returns.
0
 

Author Comment

by:emeka57
ID: 39248622
Did that and still receiving the same errors.  See below:

+                     ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-AccountPassword:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
-DisplayName : The term '-DisplayName' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\emeka\Google Drive\PowerShell\Bulk User Creation\BulkUserCreation.ps1:19 char:6
+                     -DisplayName $DisplayName -EmailAddress $Email -Description $Description`
+                     ~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-DisplayName:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
-GivenName : The term '-GivenName' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\emeka\Google Drive\PowerShell\Bulk User Creation\BulkUserCreation.ps1:20 char:6
+                     -GivenName $FirstName -Surname $Surname -PassThru -Enabled $true -Path $OU`
+                     ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-GivenName:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
 
-AccountPassword : The term '-AccountPassword' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\emeka\Google Drive\PowerShell\Bulk User Creation\BulkUserCreation.ps1:21 char:6
+                     -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -force)`
+                     ~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (-AccountPassword:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39248769
I can see lot of trailing space in your csv file, which probably causing the error..

Is the users listed in CSV got created without any issue?

Try this code...
Import-Module ActiveDirectory
Import-Module MSOnline
Set-ExecutionPolicy Unrestricted

	$Users = Import-Csv Book3.csv
	ForEach ($User in $Users)
	{
		$OU = $User.Path #"OU=Faculty,OU=Canarsie ACS (LS),DC=ascendlearning,DC=org" 
		$Name = $User.Name
		$GivenName = $User.FirstName
		$Surname = $User.LastName
		$SAM = $User.SAMAccountname
		$UPN = $User.UPN
		$Email = $User.EmailAddress
		$Description = $User.Description
                $Password = $User.Password
		$Group = $User.Group
		
		New-ADUser -Name $Name -SamAccountName $SAM -UserPrincipalName $UPN -DisplayName $Name -EmailAddress $Email -Description $Description -GivenName $GivenName -Surname $Surname -Enabled $true -Path $OU -AccountPassword (ConvertTo-SecureString -AsPlainText $Password -force) -PassThru
		#Add-ADGroupMember -Identity $Group -Member $SAM
	}

Open in new window

0
 
LVL 40

Expert Comment

by:footech
ID: 39248988
When I downloaded your CSV, I had to remove all the commas at the end of each line (actually just the header line was sufficient) in order for the import-csv to work.
When you use line continuation with backticks, typically you should have a space right before the backtick.  When I did that, and also correct "givenname" to "$givenname" in your new-aduser command, your script worked fine for me.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question