Get AccessRights - FullAccess

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.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]