Hi all,
well, two long days and nights long trying now - i give up for the moment. Adding multiple Users to Active Directory finally ended up at Corey Roth's Blog and his example script (thanks). Doesn't work yet, and i have reduced it to quite less "functionality" than i want to finally implement. Coming from "older" PowerShell scripts/commands to trying dsadd-commands (horrible to script/import/export) over Quest tools back to "clean" actual PowerShell. Seems like - i don't know, i'm helpless. And i'd really like to use the shell for doing many AD-stuff etc. And i also read many many posts. :\ Didn't end up successfully.
Environment: Windows Server 2008 R2 SP1 Domaincontroller, actual patches, running nothing else. Script running in Active Directory Module for Windows PowerShell, (editing with Notepad++)
my script:
Import-CSV "c:\scripts\Content.csv" \foreach-object{ $userprincipalname = $_.SamAccountName + "@mydomain.de" New-ADUser -SamAccountName $_.SamAccountName -UserPrincipalName $userprincipalname -GivenName $_.FirstName -Name $_.LastName -Displayname = "$_.FirstName" + "$_.LastName" -EmailAddress $_.mail -Title $_.title -OfficePhone $_.telephone -Department $_.Department -Path "OU=MY-OU,OU=Content,dc=corp,dc=mydomain,dc=net" -AccountPassword(ConvertTo-SecureString "x345Stro11nG" -AsPlainText -force) -Enabled$True -PasswordNeverExpires $True -PassThru }
Powershell error:
PS C:\scripts> .\content.ps1
Unexpected token 'New-ADUser' in expression or statement.
At C:\scripts\content.ps1:3 char:121
+ Import-CSV "c:\scripts\Content.csv" \foreach-object{ $userprincipalname = $_.SamAccountName + "@mydomain.corp"
New-ADUser <<<< -SamAccountName $_.SamAccountName -UserPrincipalName $userprincipalname - GivenName $_.FirstName
-Name $_.LastName -Displayname = "$_.FirstName" + "$_.LastName" -EmailAddress $_.mail -Title $_.title -OfficePhone
$_.telephone -Department $_.Department -Path "OU=MyOU,OU=Content,dc=mydomain,dc=corp" -AccountPassword(ConvertTo-
SecureString "x345Stro11nG"" -AsPlainText -force) -Enabled$True -PasswordNeverExpires $True -PassThru }
+ CategoryInfo : ParserError: (New-ADUser:String) [], ParseException + FullyQualifiedErrorId : UnexpectedToken
Thanks for any hints, advices...
Best, Jörg