Monday, November 28, 2022

New Active Directory user creation with email address information's for Office365 Sync. Assume you don't use inhouse exchange server

 

AD User adding script


Copy the text from here and save it to a file as NewADUser.ps1

#--------------------------------------------------------------------------------------

#This Script was Developed by Janaka (janakackv@gmail.com) 

#Script is designed to use in an environment that has AD-Sync configured with Office 365 tenant without having a Local exchange server. 

#By running the below script in PowerShell on your domain controller, Domain users can be created with add all the necessary attributes required to sync to the cloud. Then you can assign a license to your O365 Admin Centre.


#######Before your run######

#make sure to set your domain in $domain section.

#user has to input Username / SMTP ID / First name & last name etc. 


#######After the script######

#New users will be created in Default Users OU. You can move new ADUser to target OU which has been configured to Sync with O365 Tennant. 


#Define variables;

$domain = "YOU DOMAIN"

$username = Read-Host -Prompt 'Type User name(all small letters)'

$email = Read-Host -Prompt 'Input External Email Address(all small letters)'

$fname = Read-Host -Prompt 'Input First Name(First Letter CAPS)'

$lname = Read-Host -Prompt 'Input Last Name(First Letter CAPS)'

$dept = Read-Host -Prompt 'Input Department(ALL CAPS)'

$comp = Read-Host -Prompt 'Input Company(Follow standard)'


#Creating ADUser by using the above variables 

Get-Module -name ActiveDirectory

New-ADUser -sAMAccountName "$username" -name "$fname $lname" -GivenName $fname -Surname $lname -displayName "$fname $lname" -Accountpassword (Read-Host -AsSecureString "AccountPassword") -Enabled $true -OtherAttributes @{'mailNickname'="$fname";'mail'="$email";'userPrincipalName'="$username@$domain";'proxyAddresses'="SMTP:$email";'company'="$comp";'department'="$dept"}

Start-Sleep -Seconds 2


#Get User information 

Get-ADUser "$username" -Properties CanonicalName, Enabled, GivenName, Surname, Name, UserPrincipalName, samAccountName, whenCreated, PasswordLastSet  | Select CanonicalName, Enabled, GivenName, Surname, Name, UserPrincipalName, samAccountName, whenCreated, PasswordLastSet


####END OF SCRIPT####


No comments:

Post a Comment