Skip to content
April 4, 2012 / dw

Create an Active Directory user with PowerShell.

Create an Active Directory user with PowerShell.

to run this script add a period (.) and drag the scrip into the PowerShell window.


[PS] C:\Documents and Settings\Administrator\Desktop>.C:\Documents and Settings\Administrator\Desktop\newuser.ps1



$location = Read-Host "Location: "
$Firstname = Read-Host "First Name: "
$Lastname = Read-Host "LastName: "
$name = $Firstname + " " + $Lastname
$username = $Firstname[1] + $Lastname
$domain = "E2K7.dw"
$Userprincipalname = $name + "@" + $domain
$password = Read-Host "Enter password: " -AsSecureString
$Initials = $Firstname[1] + $Lastname[1]
$OrganizationalUnit = ‘E2k7.dw/DW Users’
$Profile = ‘\\Myserver\profile’
set-location $location
New-Mailbox -Name $name `
-Alias $username `
-OrganizationalUnit $OrganizationalUnit `
-UserPrincipalName $Userprincipalname `
-SamAccountName $username `
-FirstName $Firstname `
-LastName $Lastname `
-Password $password `
-ResetPasswordOnNextLogon $false `
-Database ‘CN=Mailbox Database,CN=First Storage
Group,CN=InformationStore,CN=E2K7V,CN=Servers,CN=Exchange Administrative Group
(FYDIBOHF23SPDLT),CN=Administrative Groups,CN=DAT,CN=Microsoft



Or, something I had a very difficult time with, getting the script to pass the password from the spreadsheet. If you want the script to read a spreadsheet, that’s pretty easy, but that last half of the password line alluded me.


Import-CSV d:\scripts\Recipients.csv | foreach {new-mailbox -alias $_.alias `
-name $ `
-userPrincipalName $_.UPN `
-FirstName $_.Firstname `
-LastName $_.Lastname `
-Password (Convertto-securestring $_.Password -asplainText -Force) `
-database mailboxservername\databasename" -org OUname -ResetPasswordOnNextLogon:$false}
Import-CSV d:\scripts\Recipients.csv | foreach { set-mailbox -Identity $_.alias `
-PrimarySmtpAddress ("{0}" -f $_.alias) -EmailAddressPolicyEnabled:$false}



The spreadsheet needs to be in a csv format and have the appropriate headers. For this particular script the headers would look like:


Modify to your liking of course.


One Comment

Leave a Comment
  1. lethu / May 24 2012 1:46 pm

    I need emil

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: