I've been banging away at this problem here without any solid solution. I'm attempting to pull all group data of a user from Azure/Exchange Online shared mailboxes,O365 Groups, Sharepoints, Rooms & Equipment/Resources. The purpose is to them purge the user of all of the groups/distros. I can successfully pull almost all of the users group information by using the first section of code below. However I am struggling to all grab the Rooms and Equipment/Resources groups.
hmmm
CodePudding user response:
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$FName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter users first name:","Users first name")
$LName = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Users last name","Users last name")
$Email = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Users email address","Users email address")
$UserID = $Email
$FullName = ($FName " " $LName)
$AzureCSV = "C:\Users2\Azure.csv"
$ExchangeCSV = "C:\Users2\Exchange.csv"
Import-Module AzureAD
Import-Module ExchangeOnlineManagement
Try {
#Connect to Azure AD
Connect-AzureAD
#Get the User
$User = Get-AzureADUser -ObjectId $UserID
#Get User's Group Memberships
$AzureMemberships = Get-AzureADUserMembership -ObjectId $User.ObjectId | Where-object { $_.ObjectType -eq "Group" }
#Export group memberships to a CSV
$AzureMemberships | Select DisplayName, Mail | Export-Csv -LiteralPath $AzureCSV -NoTypeInformation
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
Try {
#Connect to Exhange Online
Connect-ExchangeOnline
#Get Room mailbox permissions
$ExchangeMemberships = Get-Mailbox -Filter '(RecipientTypeDetails -eq "RoomMailbox")'
#Export room memberships to a CSV
$ExchangeMemberships | Select Identity,GrantSendOnBehalfTo | ? GrantSendOnBehalfTo -Like *$FullName* | Export-Csv -LiteralPath $ExchangeCSV -NoTypeInformation
}
Catch {
write-host -f Red "`tError:" $_.Exception.Message
}
Disconnect-ExchangeOnline -Confirm:$false
$CSV1 = Import-Csv "C:\Users2\Azure.csv"
$CSV2 = Import-Csv "C:\Users2\Exchange.csv"
#Import the CSVs
## GC = Get-Content
$csv1 = @(gc "C:\Users2\Azure.csv")
$csv2 = @(gc "C:\Users2\Exchange.csv")
# Create an Empty Array
$csv4 = @()
for ($i=0; $i -lt $csv1.Count; $i ) {
$csv4 = $csv1[$i] ', ' $csv2[$i]
}
# Output to file
$csv4 | Out-File "C:\Users2\Results.csv" -encoding default
# Delete the originals
Remove-Item C:\Users2\Azure.csv
Remove-Item C:\Users2\Exchange.csv
Invoke-Item "C:\Users2\Results.csv"
This may not be the most efficent way of doing this but it works for me. I would love to see an experts input on this. Below is the results.
What I'd like to figure out next is how to change the Identity header to Room. I'd also like to try to figure out why they are in quotes. Maybe even add a space between Mail and Identity header.