Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create User in Active Directory and Exchange. Applies to Exchange 2010 and AD 2012 or higher
Creates new user in Active Directory based on Company Standards
Import module from Active Directory and Exchange withou the need to have the tools the installed on the computer running the commands
I will communicate with AD 2012 R2 and Exchange 2010
New-HPDCUSER -Firstname John -LastName Doe -Password SUperSecretPassword
function New-CompanyUser
# First Name
# Last Name
$ActiveDirectory = New-PSSession -ComputerName fileserver
Import-Module ActiveDirectory -PSSession $ActiveDirectory -Prefix RM
$EXchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Authentication Kerberos
Import-PSSession $ExchangeSession -Prefix RM
$ou = 'OU=Users,OU=MyBusiness,DC=compny,DC=local'
$FullName = $FirstName + ' ' + $LastName
$SAM = $FirstName[0]
$SAM = $SAM + $LastName
$Password1 = ConvertTo-SecureString $Password -AsPlainText -Force
$UPN = $SAM + '@company.local'
$Path = "\\Yourfileserver\userprofiles\$SAM"
$Mailbox = 'Mailbox1001'
#Creates user in Active Directory
New-RMADUser -Name $FullName -DisplayName $FullName -GivenName $FirstName -Surname $LastName -Path $ou -AccountPassword $Password1 -PasswordNeverExpires $true -SamAccountName $SAM -UserPrincipalName $UPN -ProfilePath $Path
Add-RMADGroupMember 'SpecialGroup' $sam
Set-RMADUser $SAM -Enabled $true
#Creates Mailbox
Enable-RMMailbox -Identity $SAM -Database $Mailbox
Get-PSSession |Remove-PSSession
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment