ExchangeNerd

Powered by Ed Buford and Coffee

Archives: April 2014

Moving FSMO Roles with PowerShell

If you’ve ever had to move FSMO roles in Active Directory to another server you know it’s not as straight forward as it could should be (At least until I found PowerShell).

Open the Active Directory Module for Windows PowerShell or open PoweShell on a machine with RSAT installed and Import-Module ActiveDirectory

image

Part of the FSMO roles are Domain and part are Forest so you’ll need to use 2 commands to get the roles.
To get the Domain role holders:

Get-ADDomain | select PDCEmulator,RIDMaster,InfrastructureMaster

To get the Forest role holders:

Get-ADForest | select SchemaMaster,DomainNamingMaster

Moving roles only requires one command. Change the Target-DC to the name Domain Controller you’re moving the FSMO role(s) to.

There are 5 FSMO roles include the ones you want to move.

Move-ADDirectoryServerOperationMasterRole -Identity "Target-DC" -OperationMasterRole SchemaMaster,RIDMaster,InfrastructureMaster,DomainNamingMaster,PDCEmulator

Recover Deleted Items from Exchange Dumpster

I was having a conversation at lunch with a friend who needed to recover some items for a user from the Exchange Dumpster. So I came up with a one-liner to help you do just that but BEFORE i can really give you the one-liner I need to give you some background.

First there is a Deleted Items folder in your Exchange Mailbox. When you delete an email it goes here first (for many people that is as far as it goes but that’s another blog post…).
A user can simply look here in the their deleted Items folder and find something they have deleted if that folder has not yet been emptied.

If the Deleted Items folder has been emptied it will remain in the Deletions folder (Dumpster) for the next 14 days by default. During this time the user can use Outlook and or OWA to Recover Items that are now in the Dumpster.  I love this feature but it’s not very much fun for the user if they have deleted a lot of items lately. 

So to make things a little easier on the user you can recover all the items in PowerShell and then export them so the user can sort them to their hearts content.  The tricky part here is that you can’t drop them directly back into the mailbox you’re searching.  You can use the DiscoverySearchMailbox but I keep an admin mailbox around that I use for just such occasions. I call this mailbox SearchAdmin and it will become the Target mailbox.

The PowerShell command looks like this:

Search-Mailbox -identity ebuford -SearchDumpsterOnly -TargetMailbox SearchAdmin –TargetFolder ebufordDumpster

Search-Mailbox -identity ebuford -SearchDumpsterOnly -TargetMailbox SearchAdmin –TargetFolder ebufordDumpster

The three items in red are user mailbox you’re searching (ebuford) the target mailbox your dropping the files in (SearchAdmin) and the name of the Folder you want to dump them in (ebufordDumpster).

Once you’ve got them in the new folder you can export to a PST and then Import them back into the users mailbox. Now this isn’t the most straightforward admin task you’re going to do, but if you really want to please a user (or maybe your boss) this will make you some brownie points!

[Top]

Make today a little more productive!

Outlook is my number one tool for productivity, but when I not writing or answering email I don’t want it to distract me from whatever it is that I am doing.  To minimize  the distractions you can turn off the “Bing Bong you got your emails” notifications.

I’m using Outlook 2013 so this may look different for you, but find the Outlook Options page for you Outlook version and uncheck offending boxes.

This is how I did it for mine:

F1 

F2

F3

[Top]

Get your top 5 Errors out of your Event logs

So many times I want to know what Errors are filling up the logs on a server.
Here’s a quick PowerShell to show you the top 5 Errors in your Application or System Logs.
Use this one for Application Log Errors:

Get-EventLog -LogName Applicaiton -EntryType error | Group source,eventid | Sort count -Descending | select -First 5 | FT count,Name

And this one for System Log Errors:

Get-EventLog -LogName system -EntryType error | Group source,eventid | Sort count -Descending | select -First 5 | FT count,Name

[Top]

Office 365 PowerShell

So you’ve setup Office 365 in the Cloud – Let me be the first to congratulate you!
Kudos!   Now that that’s over you need to connect your workstation to it using PowerShell, so let’s get started.
You need to download and install a couple of files the first one is the Microsoft Online Services Sign-In Assistant for IT Professionals, download it here.

Once that is installed you need to install the Windows Azure AD Module. Go here and choose your OS (32 or 64 bit). Download and install the Module and you’re ready to get started.

Now all you have to do is connect your workstation to Office 365. Open PowerShell and type these commands:

Import-module MSOnline

This will import the Module you’ll need to make a connection to the Office 365

$Cred = Get-Credential

This will pop up a credentials box for you to put your Administrator UPN for Office 365 in.

Creds

Next create a new session based on your credentials:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic –AllowRedirection

You’ll get a warning to tell you that you’re being redirected

Session

Now Import a new PSSession based on the session you just created in the cloud.

connect-msolservice -credential $cred

And finally connect to the MS Online Service:

connect-msolservice -credential $cred

So to see the commands available now type:

Get-Command -Module msonline

[Top]

Import / Export PST files with Exchange 2010 and 2013

For many reasons we sometimes need to Import or Export all or part of a mailbox to or from a PST.  Before you can Import or Export you’ll need to have permission to actually SEE the commandlets in Exchange.

So start by getting the proper permissions you can give them to a user, in this case to ebuford:

New-ManagementRoleAssignment –Role "Mailbox Import Export" –User ebuford

If you’d rather give permissions to a security group like Administrators you can do that too:

New-ManagementRoleAssignment -Role "Mailbox Import Export" -SecurityGroup Administrators

Once you’ve given rights you’re going to need to log out and then log back in to see the commandlets.

If you’d like to know who has the role assigned to them:

Get-ManagementRoleAssignment -Role "mailbox import export"

Ok so now we have the role let’s get busy!

Let’s say you need to export a full mailbox to a PST here’s how we’ll tackle that. We will need to create an new export request using the New-MailboxExportRequest  commandlet.
Specify the username for the mailbox and then give a full UNC path for the PST file you’re exporting. You can’t use C:\PSTs\ebuford.pst it must be a full UNC path.  So if you’re trying to get to the PSTs folder on the C:\ drive of your exchange server named Exchange2013 then try this:  \\Exchange2013\C$\PSTs\ebuford.pst 

-Mailbox username -FilePath \\files\pstarchive

New-MailboxExportRequest -Mailbox ebuford –FilePath “\\FileServer\PSTs\ebuford.pst”

ok so you started the mailbox export and you want to see how it’s doing. You can get the stats for a single mailbox export like this:

Get-MailboxExportRequestStatistics ebuford\mailboxexport

But what if you have a few exports running at the same time?  Try this:

Get-MailboxExportRequest | Get-MailboxExportRequestStatistics

Ok what about Importing a PST?
Well it’s basically everything we just learned but we’re going to use the NewImportRequest Commandlet.

You can also use the Get-MailboxImportRequest and Get-MailboxImportRequestStatistics.

So far so good – now let’s talk a bit about some of the options for these commands.

Let’s say I’m exporting a pst but I don’t want objects from the deleted items folder. I can use the –ExcludeFolders parameter like this:
New-MailboxExportRequest -Mailbox ebuford  – ExcludeFolders #DeletedItems# –FilePath “\\FileServer\PSTs\ebuford.pst 

Make sure you place ## around the folder

Another option might be to only get the Inbox from a mailbox you can do this just as easily using the –IncludeFolders parameter like this:

New-MailboxExportRequest -Mailbox ebuford  – IncludeFolders #Inbox# –FilePath “\\FileServer\PSTs\ebuford.pst 

Here is a list of well- know folders:

  • Inbox
  • SentItems
  • DeletedItems
  • Calendar
  • Contacts
  • Drafts
  • Journal
  • Tasks
  • Notes
  • JunkEmail
  • CommunicationHistory
  • Voicemail
  • Fax
  • Conflicts
  • SyncIssues
  • LocalFailures
  • ServerFailures
[Top]

Exchange Server Message Tracking

This morning an engineer came to me with some questions about message tracking in Exchange. I did 2 things for him I logged onto a server showed him how to get started with message tracking in PowerShell.  Then I sent him over to Paul Cunningham’s blog ExchangeServerPro to download the “Become a Message Tracking Master book”. Yes you have to register to become a member, but it’s free and if you’re reading this you will want to that anyway.

The free book is invaluable, Go get it!

[Top]