简体   繁体   中英

Creating User Accounts in Active Directory using QAD Cmdlets in Powershell

I'm currently working on a powershell script that will look at a CSV file, take the information enclosed and (along with several values defined in the script) populate AD user attributes.

Originally I had this working, but all the predefined values were in the CSV file (that was converted from an Excel spreadsheet) but the formulas would not persist line by line.

So I moved them into the script, but it just pauses as if it's waiting on more input.

Here is what the CSV file currently will contain

FirstName,LastName,Department,Title,PhoneNumber
Joe,Schmoe,Support,Someone of Something,###-###-####

and here is the import script

Import-CSV $newHire | ForEach-Object -process {new-QADUser -ParentContainer $OU -Name = $_.FirstName $_.LastName -FirstName $_.FirstName -LastName $_.LastName -DisplayName = $_.FirstName $_.LastName -SamAccountName = $_.FirstName'.'$_.LastName -UserPrincipalName = _.FirstName'.'$_.LastName'@domain.com' -Email = _.FirstName'.'$_.LastName'@emaildomain.com' -LogonScript logon.bat -Department $_.Department -Title $_.Title -PhoneNumber $_.PhoneNumber -UserPassword p@55w0rd -Company "CompanyName"}

The variables for $OU and $newHire are working correctly and contained on shared folders accessible to my user account.

Any assistance would be greatly appreciated!

Start with this:

-Name = $ .FirstName $ .LastName

The parser is going to choke on that, thinking $_.LastName is an argument for a positional parameter.

Try this:

-Name ($ .FirstName + " " + $ .LastName)

Hard to tell what else is going on there, but it looks like everywhere you've used multiple properties of the user to set a parameter need to be fixed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM