-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBulkUserAzAdd.ps1
More file actions
26 lines (20 loc) · 2.26 KB
/
BulkUserAzAdd.ps1
File metadata and controls
26 lines (20 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
########################################################################################################################
# #
# This script takes advantage of the Azure PowerShell Az module. This is not meant to be used with the AzureRM module. #
# #
# Created by Benjamin Midyette (github.com/bustelyo) MIT License #
# #
########################################################################################################################
# Connect-AzAccount -Tenant "" -Subscription ""
$users = Import-Csv -Delimiter "," -Path "userlist.csv" # Import userlist.csv
$secureStringPassword = ConvertTo-SecureString -String "Password1" -AsPlainText -Force # Create a Secure String object to contain the password string defined here
foreach ($user in $users) {
$displayName = $user.Firstname + " " + $user.Lastname # Display Name consists of First and Last name
$domain = "lynnes.onmicrosoft.com" # Set domain to correct domain name
$userPrincipalName = $user.Firstname.ToLower()[0] + $user.Lastname.ToLower() + "@" + $domain # Changes first and last name to lowercase, then creates 'first initial' character for Principla Name/Sign in, creates the principal name from first initial, last name, and domain
$mailNickname = $user.Firstname.ToLower()[0] + $user.Lastname.ToLower()
New-AzADUser -DisplayName $displayName -UserPrincipalName $userPrincipalName -Password $secureStringPassword -MailNickname $mailNickname -ForceChangePasswordNextLogin -Confirm
Add-AzADGroupMember -MemberUserPrincipalName $userPrincipalName -TargetGroupDisplayName $user.Company -Confirm
}
# The SAM Account name (logon name) used to support clients and servers running earlier versions of the operating system.
# Mail Nickname is an 'email alias' and usually matches the SAM account name. New-AzADUser has a parameter to define the Mail Nickname with -MailNickname (string)