#Create-NewADUserO365.ps1
#3/3/15 Benjamin Hart, Unified Brands, Inc
#Created with Powershell ISE
#This powershell script will create a domain user object using a format of lastname, firstname, a SAM of first initial + last name
#It will also populate displayname, a default password, office and both proxyaddresses, the primary as used in your org and the
#Dover required O365 one. It will also verify the primary proxy address is not already used.
#With set-aduser you can alter almost any attribute of the user.
$theOU = read-host "Enter the OU name"
$Surname = read-Host "Enter the surname"
$GivenName = read-host "Enter first name"
$DisplayName = "$Surname, $GivenName"
$Password = "December1"
$name = $GivenName.substring(0,1)+$Surname
$proxyaddress = read-host "Enter the proxy address in full"
Import-Module activedirectory
import-module servermanager
#Edit the SearchBase to match your organization
$myOU = Get-AdOrganizationalUnit -Filter "Name -eq '$theOU'" -Searchbase 'OU=People,DC=Domain,DC=Root01,DC=org'
#Below verifies the Proxyaddress is not already present
Get-ADuser -filter * -Properties ProxyAddresses|?{$_.proxyaddresses -contains $proxyaddress}
$found=Get-ADuser -filter * -Properties ProxyAddresses|
Where-Object{
$_.proxyaddresses |
Where-Object{ $_ -eq $ProxyAddress }}
while (Get-ADuser -filter * -Properties ProxyAddresses|?{$_.proxyaddresses -contains $proxyaddress})
{
$proxyaddress = read-host "$proxyaddress is already in use, please try another one"
}
Write-Host "$proxyaddress is not used yet."
#Edit your locations if you choose to use this part
Switch ($Office) {
"Michigan" {
$Street = "123 Main st"
$City = "Weidman"
$State = "Michigan"
$Zip = "48898"
$scriptpath = "\\difc\netlogon\milogin1.bat"
}
"Mississippi" {
$Street = "123 Main st"
$City = "Jackson"
$State = "Mississippi"
$Zip = "39272"
$scriptpath = "\\difc\netlogon\adlogin.bat"
}
"Oklahoma" {
$Street = "123 Main st"
$City = "Pryor"
$State = "Oklahoma"
$Zip = "74361"
$scriptpath = "\\difc\netlogon\oklogin.bat"
}
"Georgia" {
$Street = "123 Main st"
$City = "Conyers"
$State = "Georgia"
$Zip = "30013"
}
}
#Edit the below to match your domain(s)
$DoverProxyAddress = "$($givenname.substring(0,1))$surname-$("unifiedbrands")-$("net")@company.mail.onmicrosoft.com"
$Description = read-host "Enter persons description"
$jobtitle = read-host "Enter the Job Title"
#Edit the below to match your locations
$office = read-host "Enter the user's location, Michigan, Mississippi, Georgia, Oklahoma or Remote"
$department = read-host "Enter the users Department"
New-ADUser -path $myOU -samaccountname $name -name $displayname -DisplayName $DisplayName -Surname $Surname -givenname $givenname -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -force) -enabled:$false
set-aduser $name -emailaddress $proxyaddress -Description $Description -Title $jobtitle -Office $office -UserPrincipalName $proxyaddress -Department $department -Company "Company, Inc"
set-aduser $name -StreetAddress $Street -city $city -state $state -PostalCode $zip
set-aduser $name -ScriptPath $scriptpath
Set-ADUser $name -Replace @{employeeType="EMPLOYEE"}
set-aduser $name -add @{proxyaddresses = ("SMTP:")+"$proxyaddress"}
set-aduser $name -add @{ProxyAddresses = ("smtp:")+"$doverproxyaddress"}
get-aduser $name
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.