# Get AccessRights - FullAccess

**URL:** <https://forums.powershell.org/t/get-accessrights-fullaccess/1612>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/get-accessrights-fullaccess/1612 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/get-accessrights-fullaccess/1612/1 "2011-12-31T18:30:00Z")

</div>

by toniino38 at 2012-12-04 07:29:38

> Hi everyone,   
>   
> I would like to improve my script below :  
>   
> [code2=powershell]$usernames = Get-MsolUser -all | select UserPrincipalName  
> Foreach ($username in $usernames)  
> {  
>   
> $listobjFullaccessrights = Get-Mailbox $username.UserPrincipalName -ResultSize unlimited | Get-MailboxPermission -ResultSize unlimited | Where-Object { ($_.AccessRights -eq "Fullaccess") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF") -and -not ($_.user -like "S\*") }   
>   
> if ($listobjFullaccessrights -ne $null) {$listobjFullaccessrights | foreach {$UPN = get-mailbox $_.user | select UserPrincipalName_  
>   
> _$requete\_fullaccess.CommandText += '("'+$username.UserPrincipalName +'","'+  
> $UPN.UserPrincipalName +'"),'_  
>   
> _}_  
>   
> _}  
> }_  
>   
> _$requete\_fullaccess.CommandText = $requete\_fullaccess.CommandText.Substring(0,$requete\_fullaccess.CommandText.length-1)  
> $requete\_fullaccess.ExecuteNonQuery()  
> $requete\_fullaccess.CommandText = ""[/code2]_  
>   
> _The purpose of this script is to send in database the mailbox’s name and e-mails which have a fullaccess on.   
> It works but it’s so long, how can i do it faster ?_  
>   
> _Thanks for helping me =)_

_by JeffH at 2012-12-05 12:31:36_

_> Nothing jumps out. Some times things take a long time to run. Although I’m not seeing where you are defining $requete\_fullaccess so maybe there is more to this that might be optimized?_

_by Infradeploy at 2012-12-09 12:00:45_

_> Remoting into o365 is slow, i can relate to the wish of optimizing the code.   
> get-mailbox is much faster then get-msoluser, cant you use that?_

_by Helmto108 at 2013-02-02 09:09:05_

> _Hi, You may be able to speed this up. You don’t need the 2 get-mailboxes in the foreach loops. No need to query exchange for information you already have._  
>   
> _Try this and let me know if its any faster._   
>   
> _[code2=powershell]$Users = get-Mailbox -resultsize unlimited  
> $export = @()_  
>   
> _$users | ForEach-Object {_  
>   
> _$temp = $null  
> $temp = New-Object -type PSobject  
> $temp = Get-MailboxPermission $_.Identity | Where-Object {($_.AccessRights -eq "Fullaccess") -and ($_.IsInherited -eq $false) -and ($_.User -notlike "NT AUTHORITY\SELF") -and ($_.user -notlike "S\*")} | Select Identity, User, AccessRights  
>   
> $export += $Temp  
>   
> }  
>   
> $export | Export-CSV C]

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:03pm UTC](https://forums.powershell.org/t/get-accessrights-fullaccess/1612/2 "2024-05-16T21:03:43Z")

</div>


