Get AccessRights – FullAccess

Welcome Forums General PowerShell Q&A Get AccessRights – FullAccess

Viewing 0 reply threads
  • Author
    Posts
    • #6558
      Participant
      Topics: 1562
      Replies: 0
      Points: 1
      Rank: Member

      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]

Viewing 0 reply threads
  • The topic ‘Get AccessRights – FullAccess’ is closed to new replies.