AVDBlueprint/scripts/assignADGroup.ps1

15 строки
626 B
PowerShell
Исходник Обычный вид История

2021-01-04 18:54:43 +03:00
param ($groupName, $userPrincipalName)
Write-Host "Adding UPN ($userPrincipalName) to group ($groupName)"
if ($null -eq (Get-AzADGroup -DisplayName "$groupName")) {
$mailNickname = $groupName -replace '[\W]',''
New-AzADGroup -DisplayName "$groupName" -MailNickname $mailNickname
}
if ($null -eq (Get-AzADGroupMember -GroupDisplayName "$groupName" | Where-Object {$_.UserPrincipalName -eq $userPrincipalName})) {
$parameters = @{
TargetGroupDisplayName = "$groupName"
MemberUserPrincipalName = $userPrincipalName
}
Add-AzADGroupMember @parameters
}