2021-03-01 18:47:24 +03:00
|
|
|
param ($groupName, $userPrincipalName)
|
|
|
|
Write-Host "Adding UPN ($userPrincipalName) to group ($groupName)"
|
|
|
|
|
2021-08-25 22:37:29 +03:00
|
|
|
if (-Not (Get-AzADGroup -DisplayName "$groupName")) {
|
2021-03-01 18:47:24 +03:00
|
|
|
$mailNickname = $groupName -replace '[\W]',''
|
|
|
|
New-AzADGroup -DisplayName "$groupName" -MailNickname $mailNickname
|
|
|
|
}
|
|
|
|
|
2021-08-26 00:33:40 +03:00
|
|
|
Start-Sleep 10
|
2021-08-25 22:37:29 +03:00
|
|
|
if (-Not (Get-AzADGroupMember -GroupDisplayName "$groupName" | Where-Object {$_.UserPrincipalName -eq $userPrincipalName})) {
|
2021-03-01 18:47:24 +03:00
|
|
|
$parameters = @{
|
|
|
|
TargetGroupDisplayName = "$groupName"
|
|
|
|
MemberUserPrincipalName = $userPrincipalName
|
|
|
|
}
|
|
|
|
Add-AzADGroupMember @parameters
|
2021-01-04 18:54:43 +03:00
|
|
|
}
|