Test2.ps1
Connect-MgGraph -ClientId 'dcb0dcea-e8d2-4561-94c2-5a18be45eaca' ` -TenantId '77a7ebb7-ae63-4259-9307-d2683e631623' ` -CertificateThumbprint '313B1483D1DED8490A7525A038C47845E3575E5B' get-mguser $a = get-mguser -UserId '2b009992-e963-4b7c-90e4-547e8c0d34c3' $a.onPremisesExtensionAttributes "https://graph.microsoft.com/v1.0/users?`$top=$batchSize&`$skip=$skip&`$filter=onPremisesExtensionAttributes/extensionAttribute14 ne 'null'" Invoke-MgGraphRequest -Method get -Uri "https://graph.microsoft.com/v1.0/users?`$top=10&`$skip=10&`$filter=onPremisesExtensionAttributes/extensionAttribute14(p:p ne 'null')" Invoke-MgGraphRequest -Method 'GET' -uri "https://graph.microsoft.com/v1.0/users?`$filter=(displayname/any(p:p eq 'lee gu'))" Invoke-MgGraphRequest -Method GET -uri "https://graph.microsoft.com/v1.0/users" Get-MgUser -Filter "NOT(onPremisesExtensionAttributes/subproperty(p:p/extensionAttribute14 ne ''))" Get-Mguser | Where-Object {$_.onPremisesExtensionAttributes.extensionAttribute14 -ne $null} Get-mguser -Filter "ID/(p:p eq '2b009992-e963-4b7c-90e4-547e8c0d34c3')" Get-MgUserLicenseDetail -UserId 'c9e8055e-cf71-4148-93b1-bd0651bb2542' get-mgbetauser | Get-Member | Measure-Object Disconnect-MgGraph Get-MgDevice -DeviceId Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/deviceManagement/managedDevices/$($Device)/wipe" Get-service | F: Get-alias | fw -Column 8 Function Get-EaiSpecificMailboxPermissions { [CmdletBinding()] param ( [string]$UserPrincipalName ) #$user = Get-MgUser -UserPrincipalName $UserPrincipalName #$user.onPremisesExtensionAttributes $ExportLoc = 'c:\temp' $UsageReport = [System.Collections.Generic.List[PSCustomObject]]::new() class UserPermissions { [string]$Identity [string]$User [string]$AccessRights [string]$IsInherited [string]$deny [string]$inheritanceType } $UsageReport = @() $mbxs = Get-exomailbox -RecipientTypeDetails 'UserMailbox' -resultsize unlimited | select-object -property Displayname,PrimarySMTPAddress,Identity #$mbxs | Foreach-Object -ThrottleLimit 5 -Parallel { foreach ($mbx in $mbxs) { $MailboxPermissions = Get-EXOMailboxPermission "$($mbx.Identity)" | Where-Object{($_.user -eq 'NT AUTHORITY\SELF') -or ($_.user -notlike "S-1-5-21*") -and ($_.IsInherited -eq $false)} foreach ($MailboxPermission in $MailboxPermissions ) { $Report = @{ Identity = $mbx.Identity User = $mbx.User AccessRights = $mbx.AccessRights IsInherited = $mbx.IsInherited deny = $mbx.deny inheritanceType = $mbx.inheritanceType } $UsageReport = $UsageReport + $Report } } $UsageReport | Export-csv "$ExportLoc\MailPermissionsOL_UserMailbox.csv" -NoTypeInformation -Append Get-EXOMailboxPermission -Identity 'diane' | gm } connect-exchangeonline Get-EaiSpecificMailboxPermissions ##Gather Data and export Start-RobustCloudCommand ` -UserPrincipalName $O365Acct ` -Recipients $mbx ` -logfile "$ExportLoc\MailPermissionsOL_RCC\out.log" ` -ScriptBlock{ } Connect-ExchangeOnline function Get-DistributionGroupMembersRecursive { [CmdletBinding()] param ( [string] $GroupName, [System.Collections.ArrayList]$groupsToSkip = (new-object -TypeName System.Collections.ArrayList) ) if ($GroupName -in $groupsToSkip) { Write-Verbose "Skipping group $GroupName as it has already been processed" return 0 } #[null]$groupsToSkip.add($GroupName) $groupsToSkip.add($GroupName) $groupMembers = Get-DistributionGroupMember -Identity $GroupName $totalCount = $groupMembers.Count Write-Verbose "Total members in group $GroupName including without nested groups:$totalCount" foreach ($member in $groupMembers) { #create array of found groups if ($member.RecipientType -eq "MailUniversalDistributionGroup") { Write-Verbose "Getting members of nested group $($member.DisplayNameName)" $totalCount += Get-DistributionGroupMembersRecursive -GroupName $member.DisplayName -groupsToSkip ([ref]$groupsToSkip) } } Write-Verbose "Total members in group $GroupName including nested groups:$totalCount" return $totalCount } Get-DistributionGroupMembersRecursive -GroupName 'IT Department' -Verbose #older code function Get-DistributionGroupMembersRecursive { [CmdletBinding()] param ( [string] $GroupName, $groupsToSkip = @() ) if ($GroupName -in $groupsToSkip) { Write-Verbose "Skipping group $GroupName as it has already been processed" return 0 } $groupsToSkip = $groupsToSkip + $GroupName $groupMembers = Get-DistributionGroupMember -Identity $GroupName $totalCount = $groupMembers.Count Write-Verbose "Total members in group $totalCount" foreach ($member in $groupMembers) { #create array of found groups if ($member.RecipientType -eq "MailUniversalDistributionGroup") { Write-Verbose "Getting members of nested group $($member.DisplayNameName)" $totalCount += Get-DistributionGroupMembersRecursive -GroupName $member.DisplayName -groupsToSkip [ref]$groupsToSkip } } Write-Verbose " Total members in group $GroupName including nested groups:$totalCount" return $totalCount } Get-DistributionGroupMembersRecursive -GroupName 'IT Department' -Verbose |