-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCreate_EntraID_Users.ps1
53 lines (44 loc) · 1.48 KB
/
Create_EntraID_Users.ps1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Enter the Tenant ID for your Azure AD
$TenantId = ""
# Populate your Domain Suffix
$DomainSuffix = ""
# List of user names to create
$UserNames = @(
"John Smith",
"Jane Doe",
"Robert Johnson",
"Emma Brown",
"Michael Davis",
"Olivia Wilson",
"William Jones",
"Emily Clark",
"Joseph Taylor",
"Sophia Lewis",
"David Anderson"
)
# login to Azure
Connect-AzAccount -TenantId $TenantId
# Loop through the list of user names and create a user for each
foreach ($UserName in $UserNames) {
# Generate a random password for each user
$Password = New-Guid
# Split the user name into first and last names
$NameParts = $UserName.Split(" ")
$FirstName = $NameParts[0]
$LastName = $NameParts[1]
# Set the display name and user principal name for the new user
$DisplayName = $UserName
$UserPrincipalName = $FirstName.ToLower() + "." + $LastName.ToLower() + "@" + $DomainSuffix
# Set up the default password for the users - this will be changed on first login
$Password = "Password@AZ104"
$Password = ConvertTo-SecureString -AsPlainText -Force $Password
# Create the new user in Microsoft Entra ID
$NewUserParams = @{
DisplayName = "$DisplayName"
UserPrincipalName = "$UserPrincipalName"
AccountEnabled = $true
ForceChangePasswordNextLogin = $true
MailNickname = $FirstName.ToLower() + "." + $LastName.ToLower()
}
$NewUser = New-AzADUser @NewUserParams -Password $Password
}