Created
July 11, 2018 13:09
-
-
Save PiotrFerenc/3b110774de970dc7e0031931eb86cb92 to your computer and use it in GitHub Desktop.
PowerShell AzureAD Groups Members
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$User = "[email protected]" | |
$PWord = ConvertTo-SecureString -String "tajnehaslo" -AsPlainText -Force | |
$Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord | |
#$UserCredential = Get-Credential | |
Connect-MsolService -Credential $Credential | |
$Groups = Get-MsolGroup -All | |
foreach ($Group in $Groups) | |
{ | |
$Group_GUID = $Group.ObjectId | |
$Group_DisplayName = $Group.DisplayName | |
$Group_Email = $Group.EmailAddress | |
$Group_GroupType = $Group.GroupType | |
$GroupMembers = Get-MsolGroupMember -GroupObjectId $Group_GUID | |
foreach ($GroupMember in $GroupMembers) { | |
if($GroupMember.GroupMemberType -eq "User"){ | |
$userMember = Get-MsolUser -ObjectId $GroupMember.ObjectId; | |
$userData = @{ | |
"Id" = $userMember.ObjectId; | |
"UserPrincipalName" = $userMember.UserPrincipalName; | |
"DisplayName" = $userMember.DisplayName; | |
"Department" = $userMember.Department; | |
"LastName" = $userMember.LastName; | |
"MobilePhone" = $userMember.MobilePhone; | |
"PhoneNumber" = $userMember.PhoneNumber; | |
} | |
$UserObj = New-Object -TypeName PSObject -Property $userData | |
$user = $UserObj | select Id, UserPrincipalName, DisplayName,Department,LastName, MobilePhone,PhoneNumber; | |
Write-Host $userData.Id " " $userData.DisplayName " " $userData.Department " " $userData.MobilePhone " " $userData.PhoneNumber | |
Write-Output $user; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment