header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Create users with default password and add to default group
Last Post 17 Mar 2010 02:44 AM by tranceash. 0 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
tranceashUser is Offline
New Member
New Member
Posts:5
Avatar

--
17 Mar 2010 02:44 AM  
I wrote this as I could not find any example script to do this and would like to share it with others.
----------------
foreach ( $record in (Import-Csv e:\scripts\users.csv)) {
$command = "New-ADUser "
$DefaultGroup = $record.DefaultGroup
$name = $record.SamAccountName
foreach ( $attribute in
(Get-Member -InputObject $record -MemberType NoteProperty) ) {
$value = $record.($attribute.Name)
if (($value) -and ($attribute.Name -cne "DefaultGroup")) {
$command += " -$($attribute.Name) '$value'"
}
}
$common = " -Enabled 1 –ChangePasswordAtLogon 1 -AccountPassword
(ConvertTo-SecureString 'p@ssw2010' -AsPlainText -force)"
$command+=$common
#Write-Host $command
Invoke-Expression $command
Add-ADGroupMember $DefaultGroup $name
}
-----------------
users.csv
-----------------
Name,GivenName,Surname,DisplayName,SamAccountName,UserPrincipalName,Description,Department,Path,HomeDrive,HomeDirectory,DefaultGroup
Jennifer Wong,Jennifer,Wong,Jennifer Wong,JWong,JWong@bglcorp.local,Wiki Editor,Support,"OU=Users,OU=TEST,DC=corp,DC=local","R:","\\dc1\home\JWong",Support
-----------------

Also does anyone know of a method where I can add the other attributes from the csv and one additional common method  for example
import-csv c:\users.csv | New-AdUser $_, -Enabled 1
this gives me an error on $_ but the new-aduser already uses the for-each object so I am confused here ?


You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer