PowerShell – Exchange 2007

Jeg vil i denne blog-post prøve at samle nogle af de PS script jeg har testet og som er relateret til Exchange 2007.
Alle script bliver gemt og afviklet inde fra PowerGUI (www.powergui.org).
Jeg har tidligere lavet en kort blog-post omkring PowerGUI her – http://jravn.dk/?p=43
Det hele er testet af på en såkaldt “Admin PC” med Windows 7 RC.
Det er vigtigt at man afvikler script og PowerGUI med de fornødne rettigheder. Typisk vil man vælge en domain admins account.
Følgende software er installeret i nedenstående rækkefølge.

Installer Exchange 2007 EMC SP1 og vælg “Custom Exchange Server installation”.
Vælg herefter kun “Managemnet Tools”.

Download link (32-Bit).
http://www.microsoft.com/downloads/details.aspx?FamilyID=6be38633-7248-4532-929b-76e9c677e802&displaylang=en

Installerer herefter seneste SP eller Update Rollup (Exchange 2007 SP1 Rollup Update 9).
http://www.microsoft.com/downloads/details.aspx?FamilyID=55320be2-c65c-48bb-bab8-6335aa7d008c&displaylang=en#filelist

Installer RSAT til Windows 7 RC og vælg alle RSAT features.
http://www.microsoft.com/downloads/details.aspx?FamilyID=f6c62797-791c-48e3-b754-c7c0a09f32f3&displaylang=en#filelist

Installer Seneste Quest AD cmdlets.
http://www.quest.com/powershell/activeroles-server.aspx

Installer Seneste PowerGUI. Under installationen vælg, som vist på nedenstående billede.
http://powergui.org/downloads.jspa

 

Jeg er nu klar til at indsætte/kopiere mine ønskede script ind i PowerGUI.
For alle script i PowerGUI, gælder det, at man nemt kan eksportere visning/resultat til csv, html eller xml.
Jeg opretter forinden en folder, som jeg kalder WIN Exchange PS.

 

Code – Mailbox Seize Report. (Download link)

#Mailbox Size Report
Get-Mailbox -ResultSize ‘Unlimited’| select @{Name=”User Name”;expression={$_.displayname}},
@{Name=”Department”;expression={(get-user $_.alias).department}},
@{Name=”Storage Group”;expression={$_.database}},
@{Name=”Total Size (MB)”;expression={(get-mailboxstatistics $_).totalitemsize.value.toMB()}},
@{Name=”ItemCount”;expression={(get-mailboxstatistics $_).itemcount}},
@{Name=”LastLogonTime”;expression={(get-mailboxstatistics $_).LastLogonTime}} | Sort-Object -property  ‘Total Size (MB)’ -descending

Visning i PowerGUI.

 

Code – Mailbox Size Report – Top 10. (Download link)

#Mailbox Size Report – Top 10
Get-Mailbox -ResultSize ‘Unlimited’| select @{Name=”User Name”;expression={$_.displayname}},
@{Name=”Department”;expression={(get-user $_.alias).department}},
@{Name=”Storage Group”;expression={$_.database}},
@{Name=”Total Size (MB)”;expression={(get-mailboxstatistics $_).totalitemsize.value.toMB()}},
@{Name=”ItemCount”;expression={(get-mailboxstatistics $_).itemcount}},
@{Name=”LastLogonTime”;expression={(get-mailboxstatistics $_).LastLogonTime}} | Sort-Object -property  ‘Total Size (MB)’ -descending | select -first 10

Reference til ovenstående.
http://telnet25.wordpress.com/2009/07/02/powergui-get-mailbox-displaynamedepartmentstoragegrouptotalsize-mbitemcount/

Code – Storage Groups Statistics. (Download link)

#Storage Groups Statistics
Get-MailboxDatabase | Select Identity,
@{Name=”Size (GB)”;Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = ““” + $objitem.server + “`” + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + “$”+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}},
@{Name=”Size (MB)”;Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = ““” + $objitem.server + “`” + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + “$”+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1024KB; [math]::round($size, 2)}},
@{Name=”No. Of Mbx”;expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}} | Sort-Object -property  ‘Size (GB)’ -descending | Format-table -AutoSize

Visning i PowerGUI.

Med denne code kan man se, hvilke nye brugere der skal fordeles rundt i de enkelte maildatabaser udfra størrelse (GB) og antal mailbokse.
Reference til ovenstående.
http://exchangeshare.wordpress.com/2009/07/27/exchange-2007-database-statistics-in-powershell/

Code – List of mailbox who last logon time is older then 30 days.
Get-MailboxStatistics | where {$_.Lastlogontime -lt (get-date).AddDays(-30)} | Select displayName,LastLoggedOnUserAccount,LastLogonTime

Code – Mailboxes with forward address.
Get-Mailbox | Where {$_.ForwardingAddress -ne $null} | Select Name, ForwardingAddress, DeliverToMailboxAndForward

Code – Mailboxes with quota limit not set to default.
Get-Mailbox | Where {$_.UseDatabaseQuotaDefaults -eq $false} | Select Name, IssueWarningQuota, ProhibitSendQuota, ProhibitSendReceiveQuota

Code – Users with Send on Behalf Of set.
Get-Mailbox | Where {$_.GrantSendOnBehalfTo -ne $null} | Select Name, GrantSendOnBehalfTo

Reference til ovenstående.
http://smtpport25.wordpress.com/2009/05/26/powershell-to-get-the-list-of-user-who-last-logon-time-is-older-then-30-days/
http://exchangeshare.wordpress.com

PowerShell links.
http://blogs.msdn.com/PowerShell/
http://social.technet.microsoft.com/forums/en-US/winserverpowershell/threads/
http://www.microsoft.com/technet/scriptcenter/scripts/message/exch2007/default.mspx?mfr=true
http://www.exchangeninjas.com/PSSCategories

Comments are closed.