I'm running a report with the below script.
All our users have an EmployeeID field populated. So I had to create the dump.txt file with:
Get-ADUser-Filter'employeeid -like "*" -and employeeid -notlike "UKGeneric"'-Properties employeeid
-searchbase"OU=IT Services,DC=uk,DC=MyCompany,DC=com" | Select SAMAccountName | out-file-dump.txt
-searchbase"OU=IT Services,DC=uk,DC=MyCompany,DC=com" | Select SAMAccountName | out-file-dump.txt
I couldn't work out how to get the above into a variable and then pass it to the below Get-Mailbox script. I couldn't work out, once adding the above into a variable how to pass it down the pipeline to something that Get-Mailbox would understand.
Any ideas?
also any advice on how I could make the below more efficient would be gratefully received. It takes ages in an 18000 mailbox environment
############################################################
#Mailbox report
#Pulls mailboxes only (not shared Mailboxes) from AD
#and lists out the following information.
# DisplayName
# Current Size of:
# Inbox
# Deleted Items(not including Dumpster)
# Sent Items
# Calendar
#The outputs to CSV with the columns in above order
#Sorted by total Mailbox Size.
############################################################
$mailboxes= @()
$mailboxes=Get-Content c:\Temp\dump.txt | Get-Mailbox | sort
$report= @()
foreach ($mailboxin$mailboxes)
{
$inboxstats=Get-MailboxFolderStatistics$mailbox-FolderScope Inbox | Where {$_.FolderPath-eq"/Inbox"}
$deletedstats=Get-MailboxFolderStatistics$mailbox | Where {$_.FolderPath-eq"/Deleted Items"}
$sentitemstats=Get-MailboxFolderStatistics$mailbox | Where {$_.FolderPath-eq"/Sent Items"}
$calendarstats=Get-MailboxFolderStatistics$mailbox | Where {$_.FolderPath-eq"/Calendar"}
Write-Host"Getting Stats for "$mailbox.DisplayName-ForegroundColor Green
$mbObj=New-Object PSObject
$mbObj | Add-Member-MemberType NoteProperty -Name"Display Name"-Value$mailbox.DisplayName
$mbObj | Add-Member-MemberType NoteProperty -Name"Inbox Size (Mb)"-Value$inboxstats.FolderandSubFolderSize.ToMB()
$mbObj | Add-Member-MemberType NoteProperty -Name"Deleted Items(MB)"-Value$deletedstats.FolderAndSubfolderSize.ToMB()
$mbObj | Add-Member-MemberType NoteProperty -Name"Sent Items(MB)"-Value$sentitemstats.FolderAndSubfolderSize.ToMB()
$mbObj | Add-Member-MemberType NoteProperty -Name"Calendar(MB)"-Value$calendarstats.FolderAndSubfolderSize.ToMB()
$report+=$mbObj
}
$report | Export-Csv c:\Temp\Report.csv-NoTypeInformation
#Mailbox report
#Pulls mailboxes only (not shared Mailboxes) from AD
#and lists out the following information.
# DisplayName
# Current Size of:
# Inbox
# Deleted Items(not including Dumpster)
# Sent Items
# Calendar
#The outputs to CSV with the columns in above order
#Sorted by total Mailbox Size.
############################################################
$mailboxes= @()
$mailboxes=Get-Content c:\Temp\dump.txt | Get-Mailbox | sort
$report= @()
foreach ($mailboxin$mailboxes)
{
$inboxstats=Get-MailboxFolderStatistics$mailbox-FolderScope Inbox | Where {$_.FolderPath-eq"/Inbox"}
$deletedstats=Get-MailboxFolderStatistics$mailbox | Where {$_.FolderPath-eq"/Deleted Items"}
$sentitemstats=Get-MailboxFolderStatistics$mailbox | Where {$_.FolderPath-eq"/Sent Items"}
$calendarstats=Get-MailboxFolderStatistics$mailbox | Where {$_.FolderPath-eq"/Calendar"}
Write-Host"Getting Stats for "$mailbox.DisplayName-ForegroundColor Green
$mbObj=New-Object PSObject
$mbObj | Add-Member-MemberType NoteProperty -Name"Display Name"-Value$mailbox.DisplayName
$mbObj | Add-Member-MemberType NoteProperty -Name"Inbox Size (Mb)"-Value$inboxstats.FolderandSubFolderSize.ToMB()
$mbObj | Add-Member-MemberType NoteProperty -Name"Deleted Items(MB)"-Value$deletedstats.FolderAndSubfolderSize.ToMB()
$mbObj | Add-Member-MemberType NoteProperty -Name"Sent Items(MB)"-Value$sentitemstats.FolderAndSubfolderSize.ToMB()
$mbObj | Add-Member-MemberType NoteProperty -Name"Calendar(MB)"-Value$calendarstats.FolderAndSubfolderSize.ToMB()
$report+=$mbObj
}
$report | Export-Csv c:\Temp\Report.csv-NoTypeInformation