-
Notifications
You must be signed in to change notification settings - Fork 3
/
users.ps1
41 lines (34 loc) · 1.46 KB
/
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
function CreateUser {
param(
[Parameter()]
[string] $upn,
[Parameter()]
[string] $displayName,
[Parameter()]
[string] $groupName
)
$userObjectId = $(az ad user list --upn $upn --query "[0].objectId")
if($userObjectId){
Write-Host "Skip"
} else {
Write-Host "Create User"
$userObjectId=$(az ad user create --display-name $displayName --password "!ecret0Qwertz" --user-principal-name $upn --query objectId -o tsv)
az ad group member add --group $groupName --member-id $userObjectId
}
Write-Host "User configured: $upn $groupName"
}
# https://docs.microsoft.com/en-us/cli/azure/ad/group?view=azure-cli-latest#az-ad-group-create
$groupName = "Encom"
$groupObjectId=$(az ad group list --display-name Encom --query [0].objectId -o tsv)
if($groupObjectId){
Write-Host "Skip Group"
} else {
Write-Host "Create Group"
$groupObjectId=$(az ad group create --display-name $groupName --mail-nickname $groupName --query objectId -o tsv)
az ad group member add --group $groupName --member-id $userObjectId
#az ad group owner add --group $groupName --owner-object-id
}
CreateUser "[email protected]" "Kevin Flynn" $groupName
CreateUser "[email protected]" "Alan Bradley" $groupName
CreateUser "[email protected]" "Ed Dillinger" $groupName
CreateUser "[email protected]" "Walter Gibbs" $groupName