Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

I'm sure I'm doing this wrong

$
0
0

I've been doing this the same way for a while but wondering if there's a better way.

Currently when I run a script that needs to do any analysis on on mailboxes I load them all into a variable. 

With 24000 mailboxes that takes a long time and uses what I've seen up to 7Gb of memory which on a shared VM Management box makes me unpopular with the team.

Example script below

$mailboxes=Get-Mailbox-ResultSize Unlimited

$panalisys= @()


foreach ($mbin$mailboxes)
{
$defperm=Get-MailboxFolderPermission-Identity$mb.Alias-User Default | Select-Object User, @{l="AccessRights";e={$_.AccessRights}}
$userDetails=Get-ADUser
$panalisys=New-Object PSObject
$panalisys | Add-Member-MemberType NoteProperty -Name'MBName'-Value$mb.DisplayName
$panalisys | Add-Member-MemberType NoteProperty -Name'User'-Value$defperm.User
$panalisys | Add-Member-MemberType NoteProperty -Name'SMTPAddress'-Value$mb.PrimarySMTPAddress
$panalisys | Add-Member-MemberType NoteProperty -Name'AccessRights'-Value$defperm.AccessRights
$panalisys | Add-Member-MemberType NoteProperty -Name'Department'-Value$userDetails.Department
$p +=$panalisys
}
$p | ?{$_.AccessRights-ne"None"} | Export-Csv c:\ScottTools\permanal.csv-NoTypeInformation

So I'm loading the mailboxes into the $mailboxes variable then running Get-MailboxFolderPermission and Get-ADUser to get the info I need.

This is to allow a team to talk to people with their Default Access on their mailbox set to anything but none. This takes hours and a lot of memory.

I'm guessing I'm probably doing it in an inefficient way. Any advice much appreciated.


Viewing all articles
Browse latest Browse all 6937

Trending Articles