-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProduct_Examples_AzureAd.ps1
38 lines (31 loc) · 1.76 KB
/
Product_Examples_AzureAd.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
#Adding Users to AzureADgroup from text file of UPN
$group1 = "93345231-7454-4629-943b-e4245426bf" #
Get-Content C:\users.txt | ForEach-Object{$user=$_.trim();$user;$upn= $user
$getazureaduser = Get-AzureADUser -Filter "userprincipalname eq '$($upn)'"
Add-AzureADGroupMember -ObjectId $group1 -RefObjectId $getazureaduser.ObjectId
}
##################################################################
#Removing Users to AzureADgroup from text file of UPN
$group1 = "93345231-7454-4629-943b-e4245426bf" #
Get-Content C:\users.txt | ForEach-Object{$user=$_.trim();$user;$upn= $user
$getazureaduser = Get-AzureADUser -Filter "userprincipalname eq '$($upn)'"
Remove-AzureADGroupMember -ObjectId $group1 -MemberId $getazureaduser.ObjectId
}
##################################################################
#Check if user is Already member of group
$group1 = "93345231-7454-4629-943b-e4245426bf" #
$getazmembership = Get-AzureADUserMembership -ObjectId “UserObjectId”
if($getazmembership.objectId -contains $group1){
write-host “User is already member of the group group1”
}
##################################################################
#ADD Administrators to Role
Get-MsolRole | Sort Name | Select Name,Description #check role name
$roleName = "Lync Service Administrator"
Get-content c:\users.txt | foreach-object{$_;
Add-MsolRoleMember -RoleMemberEmailAddress $_ -RoleName $roleName
}
##################################################################
#Checking for AzureAD user provisioning errors
Get-MsolUser -HasErrorsOnly | ft DisplayName,UserPrincipalName,@{Name="Error";Expression={($_.errors[0].ErrorDetail.objecterrors.errorrecord.ErrorDescription)}} -AutoSize
##################################################################