Monthly Archives: September 2015

Exchange Console Commands

I have been managing a Exchange server since Exchange 2003. Current on 2010 and planning on upgrading to 2013 in the next month or so. Over the years I’ve been collecting snippets of useful commands which have served me well so here is my go to list. In almost all examples anything being exported/imported is using a directory called c:\ExFiles and in my examples the server is EXServer. Replace (alias) in all examples with the actual mailbox alias:

Export out Mailboxes as PST

Export list of all mailboxes by alias
Get-Mailbox| Select Alias | Export-CSV C:\ExFiles\Alias.csv

Export mailboxes based on a csv list:
foreach ($i in (Import-Csv C:\ExFiles\Alias.csv)) { New-MailboxExportRequest -Mailbox $i.Alias -FilePath "\\EXServer\c$\ExFiles\$($i.Alias).pst" }

Export individual mailboxes:
New-MailboxExportRequest -Mailbox (alias) -FilePath "\\EXServer\c$\ExFiles\(alias).pst"

Export out only Calendar items from a mailbox then import them into another mailbox

Export calendar items from a mailbox:
New-MailboxExportRequest -Mailbox (alias) -FilePath \\EXServer\c$\ExFiles\TempPSTFile.pst -IncludeFolders "#Calendar#"

Import calendar items to a mailbox:
New-MailboxImportRequest -Mailbox (alias) -FilePath \\EXServer\c$\ExFiles\TempPSTFile.pst -IncludeFolders "#Calendar#"

Check Import/Export commands and clear then

Check import status:
Get-MailboxImportRequest

Check export status:
Get-MailboxExportRequest

Clear completed import requests:
Get-MailboxImportRequest -Status Completed | Remove-MailboxImportRequest

Clear completed export requests:
Get-MailboxExportRequest -Status Completed | Remove-MailboxExportRequest

Retention Policy Commands

Get all user mailboxes without a retention policy
Get-Mailbox -ResultSize unlimited -RecipientTypeDetails "UserMailbox" | Where-Object {$_.RetentionPolicy -eq $null}

Assign the default retention policy to all mailboxes without one
Get-Mailbox -ResultSize unlimited -RecipientTypeDetails "UserMailbox" | Where-Object {$_.RetentionPolicy -eq $null} | Set-Mailbox -RetentionPolicy "Default Archive and Retention Policy"

User Permissions

Export out a list of users who have access to other mailboxes other then their own
Get-Mailbox | Get-MailboxPermission | where {$_.user.tostring() -ne "NT AUTHORITY\SELF" -and $_.IsInherited -eq $false} | Select Identity,User,@{Name='Access Rights';Expression={[string]::join(', ', $_.AccessRights)}} | Export-Csv -NoTypeInformation c:\ExFiles\mailboxpermissions.csv

Remove a users permission from all mailboxes
Get-Mailbox | Remove-MailboxPermission -User (UserID) -AccessRights FullAccess -InheritanceType All

Remove a users permission to a single mailbox
Remove-MailboxPermission -Identity (alias) -User (UserID) -AccessRights ReadPermissions -InheritanceType All

Mailbox and Database Information

Get the overall status of each database:
Get-MailboxDatabase -Status | ft name,databasesize,availablenewmailboxspace -auto

Export out the size of each mailbox in a database:
Get-MailboxStatistics -Database "Mailbox Database 1" | Select DisplayName, ItemCount, TotalItemSize | Sort-Object TotalItemSize -Descending | Export-CSV C:\ExFiles\MBSizes1.csv

Get size of a single mailbox
Get-MailboxStatistics -identity alias | Select DisplayName, ItemCount, TotalItemSize

Deleting Items

Delete all disabled mailboxes:
Get-MailboxStatistics -Database "Mailbox Database 1" | where {$_.DisconnectReason -eq "Disabled"} | foreach {Remove-StoreMailbox -Database $_.database -Identity $_.mailboxguid -MailboxState Disabled}

Delete a individual disabled mailbox:
Remove-StoreMailbox -Database "Mailbox Database 1" -Identity (alias) -MailboxState SoftDeleted

Delete recoverable deleted items based on a alias list
foreach ($i in (Import-Csv C:\ExFiles\alias.csv)) { Search-Mailbox -Identity $i.alias -SearchDumpsterOnly -DeleteContent }

Delete all recoverable deleted items
Search-Mailbox –identity (alias) –SearchDumpsterOnly –DeleteContent

Hopefully these help someone out as much as they have me.

Generation 2 HyperV Hosts and ISO Files

A problem I have run into recently with installing Server 2012 R2 as a virtual machine on Server 2012 R2 HyperV server was I could not get the iso file to boot. Well, at least that is what I though the problem was. The virtual DVD drive with the Server 2012 iso was at the top of the boot order but it seemed to keep skipping it. After searching, and not particularly well because I barely understood what I was searching for, I found a TechNet blog that was describing my problem here: http://blogs.technet.com/b/jhoward/archive/2013/11/11/hyper-v-generation-2-virtual-machines-part-9.aspx. Long story short the gen 2 hosts are popping up the “Press any key to boot off of CD/DVD” message but not waiting for someone to press a key. Therefor it skips the CD/DVD and goes to other options, namely a blank hard drive then usually a network card. So it turns out there is a solution to this, changing the boot files to no longer prompt for a key press but to start your setup automatically.

To do this you need to get the Windows Automated Install Kit (AIK). Download that here: http://www.microsoft.com/en-us/download/details.aspx?id=39982 and of the many options you only really need to install the Deployment Tools and the Windows Preinstallation Environment (Windows PE) parts. Once these are installed here is how to modify your Server 2012 ISO.

  • Unzip the contents of your Server 2012 or 2012 R2 ISO to a directory such as c:\Win2012
  • Navigate to C:\Win2012\efi\microsoft\boot
  • Rename cdboot.efi to cdboot_prompt.efi then rename cdboot_noprompt.efi to cdboot.efi
  • Rename efisys.bin to efisys_prompt.bin then rename efisys_noprompt.bin to efisys.bin
  • Open up the “Deployment and Imaging Tools Environment” as a administrator (under Start -> Windows Kits -> Windows ADK)
  • Type the following command to create a new iso file called Win2012-NoPrompt.iso in the root of your C drive that will no longer prompt for a key: oscdimg -bC:\Win2012R2\boot\etfsboot.com -m -o -u2 -lServer2012R2 -udfver102 -bootdata:2#p0,e,b"C:\Win2012R2\boot\etfsboot.com"#pEF,e,b"C:\Win2012R2\efi\microsoft\boot\efisys.bin" C:\Win2012R2 c:\Win2012R2-NoPrompt.iso
  • Exit the command prompt

You can also use the Windows AIK to preload updates into your image or drivers but that’s a topic for another post.