Retrieve Mailbox Migration errors for Office365

When you have a lot of mailboxes to migrate, Microsoft’s provided method of viewing the errors involves a tedious amount of clicking by logging into the portal, selecting Exchange, Migration, View details, scroll down to find a failure, select the user, click view details.

Viewing Migration status in Office365


Rather than use the tedious method of going into the details, selecting a user and then viewing details, run the following powershell script (once connected using the previous office365 connection script)

get-migrationuser -status failed  | get-migrationuserstatistics | select identity,emailaddress,recipienttype, error,bytestransferred |export-csv c:\temp\migrationstatus.csv

I also have a simple loop that gets me the status once an hour. Obviously change the email address’s appropriately.

while (1)
$a=(get-migrationuser | out-string)
send-mailmessage -to [email protected] -subject “Company Migration Stats” -from [email protected] -smtpserver  -body $a
start-sleep -seconds 3600

Find mailboxes that have the Email Address Policy disabled

Took me a while to work this one out but the powershell line for this is

Or you could switch it to the following but this is less easy to read for junior techs to understand as the ! is not necessarily obvious.

Commenting out command in batch file gotcha.

I’ve been working on a batch file script (yes I know I am meant to be using powershell) and kept getting a “The syntax of the command is incorrect”.

My code is as follows:-

reg query “hklm\software\microsoft\windows\currentversion\windowsupdate\auto update\Rebootrequired”
if not errorlevel 1 (
::theKey exists therefore we need to do a reboot
echo reboot is required from previous windows updates.

The :: is a quick and tidy shortcut to rem out a statement in a batch file.

However – today I found out that you cannot use this trick within an if statement. Instead the :: needs to become rem

So the script becomes

if errorlevel 1 (
rem theKey exists therefore we need to do a reboot
echo reboot is required from previous windows updates.

For what it’s worth this is a snippet of code from a script that detects if windows updates are required, installs them, emails the log file and then reboots if required. The step above comes from a recent discovery that the patch detection returns no patches needed if the server is still in a pending reboot after patches were applied (typically because the shutdown failed to take place)

“set u” tip

Typing “set” from a command prompt will show the environment variables currently in use in that particular command prompt session. As I do a lot of batch file scripting I tend to give my variable names a two character prefix of xx. This enables me to see the status of all my variables at the end of the set statement.  Yes I know that I should really use zz but historically I had a case to use x and therefore I’ve stuck with xx.

Anyway, about a month ago I accidentally hit the enter key too quickly but stumbled across the fact that you don’t actually need to complete the set statement from a command prompt in order to see variables and typing in “set x” will show you only the variables beginning with x.

If you change the set statement to be “set u” you return a lot of the information that you were probably trying to obtain – the username, domain,dns and profile location – all very quickly and tidy.  I thought this was really neat, told my tech support guys this trick and they’ve used it several times. Yesterday I was on a support session with Microsoft and was pleased to see they used the exact same command. to Flickr greasemonkey script updated.

I updated my greasemonkey script to work with the new cache names. This script automatically links to the flickr photos tagged with the geocache name ie GC1NMKA
When I first wrote the script back in 2005 I knew very little about greasemonkey scripts and unfortunately not a lot has changed. However I realized that the script broke as it was looking for the characters GC followed by 4 uppercase alphanumeric characters. New caches now have 5 characters so I needed to fix this.

A quick change to the script now looks for GC followed by any number of uppercase alphanumeric characters and can be found by going to geocache2flickr with a greasemonkey enabled browser and installing the script. This will be the official location but will also be available on the website.
Screenshot of website showing link to flickr page

A whole podcast just for me!

A couple of admins posted for questions for some future interviews that they had in the pipeline so I sent in an email about scripting. I’m currently proficient in batch file scripting but really struggled with Powershell scripting which is unfortunate as it looks like this is where admin scripting is going in 2008 with Windows 2008 and Exchange2007. So Steve kindly produced a 10 minute podcast that answered my questions about getting started in Powershell and that was all that was in it – a whole podcast produced for me (but I don’t mind other people listening to it either)- Thanks very much Steve!

Nmap scripting.

I’ve toyed with nmap tonight to try and speed up some scripting across the lan scripts – currently I have a script that copies files across the lan, by checking each ip in turn to see if the machine is there and then copies it across – it’s very laborious and slow – I started it at 6pm tonight and it’s still running now at 10.24pm (It copies 3*100mb files across the lan).
I think by using nmap to ping sweep the lan and feed the results to a loop batch file it’ll be much quicker.
The nmap and dos script is this :-

nmap -sP -oG pclist.txt
for /F “skip=2 tokens=2” %%i in (‘find “Status: Up” pclist.txt’) do echo %%i is alive!

Just replace the echo bit with the command you want to run.