Generate Random Password for Bulk Office 365 User Provision

Please refer to the following steps on how to we generate Random Password for bulk Office 365 User Provision rather than using the same password for all the newly provisioned Office 365 Users for first login due to security concern

  1. We will refer to the ASCII table (Refer to the Table below) to identify the Character that we would like to use
  2. Requirement of the Password must include mixture of Small, Capital, Numeric and symbol, and the following simple PowerShell to address this
$Capital=[char[]] (Get-Random -input $(65..90) -Count 1) -join "" #Randomly get 1 Capital Letter 
$Small=[char[]] (Get-Random -input $(97..122) -Count 1) -join "" #Randomly get 1 Small Letter 
$Number=[char[]] (Get-Random -input $(48..57) -Count 1) -join "" #Randomly get 1 Number 
$Special=[char[]] (Get-Random -input $(33..47) -Count 1) -join "" #Randomly get 1 Special Symbol  
$Password = "Welcome"+$Capital+$Special+$Small+$Number

Prepare a CSV File (Userlist.csv) with Users’ UPN name only and assign a Random Password for each individual users. Finally, Export the results to a new CSV File

$Users=Import-csv C:\Temp\UserList.csv
$Result = @()
foreach($user in $users) { 

$Capital=[char[]] (Get-Random -input $(65..90) -Count 1) -join "" #Randomly get 1 Capital Letter 
$Small=[char[]] (Get-Random -input $(97..122) -Count 1) -join "" #Randomly get 1 Small Letter 
$Number=[char[]] (Get-Random -input $(48..57) -Count 1) -join "" #Randomly get 1 Number 
$Special=[char[]] (Get-Random -input $(33..47) -Count 1) -join "" #Randomly get 1 Special Symbol  

$Password = "Welcome"+$Capital+$Special+$Small+$Number

$TempResult = New-Object System.Object
$TempResult | Add-Member -MemberType NoteProperty -Name 'UPN' -Value $user.UserPrincipalName
$TempResult | Add-Member -MemberType NoteProperty -Name 'Password' -Value $Password 

$Result += $TempResult

}
#Export the Result to a new CSV File 
$Result | Export-csv C:\Temp\password.csv -NoTypeInformation

The content of the password.csv file

UPN Password
[email protected] WelcomeC+u4
[email protected] WelcomeJ$g3

ACSII Table for Reference

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top