Category Archives: Server

Restoring deleted items from Public Folders natively

This morning I had a user call up and say that half the meeting room calendars (which are public folders) were empty. I checked via Exchange Management Console and could confirm that there were no items. However under the statistics for the folder, I noticed that it was showing a total deleted items size.

Deleted Items meeting room

I decided to check this out through ExFolders (Exchange 2010 replacement for PFDAVAdmin) and did come across a problem as I was getting the error “An error occurred while trying to establish a connection to the exchange server. Exception: the Active Directory user wasn’t found”. To get past this issue open ADSIEDIT and select Configuration from the Well Known Naming Context drop down menu. Then drill down to Configuration> Services> Microsoft Exchange> Domain Name> Administrative Groups> First Administrative Group> and then delete the Servers object. This can sometimes be left behind from old Exchange 2003 installs. As soon as that is gone then ExFolders can continue (please read the “read me” for ExFolders as it does specify to run the reg edit file and also to move ExFolders.exe to your Exchange location\bin\ folder, which is generally in <drive>:\Program Files\Microsoft\Exchange Server\V14\Bin. It will crash otherwise).

ExFolder Deleted contents

After finding one of the folders that had its content deleting I noticed that at the bottom, there is a “normal contents” and “deleted contents” radio buttons. Unsurprisingly, selecting “deleted contents” brings up the list of deleted items. To restore them it is a simple task of selecting the items, right clicking and selecting “restore items”. Bingo the items are back and I didn’t even need to get out of my chair to get to the backup tapes. Which is handy as it is in the opposite direction to the pub…



SQL Server not starting after an update

So this morning after the patch weekend following Microsofts Patch Tuesday I updated our SQL 2008 R2 server with a security patch (KB2494088) and rebooting the MSSQL Server service refused to work. It would start up but when trying to login all you got in the SSMS(SQL Studio Management Studio) was “login failed for user. Reason: Server is in script upgrade mode. Only administrator can connect at this time”

Upgrade script

And after 2 minutes the SQL service would stop. And you’re back to square 1. In the event log all i was seeing was the following two errors:

Script level upgrade for database ‘master’ failed because upgrade step ‘sqlagent100_msdb_upgrade.sql’ encountered error 598, state 1, severity 25. This is a serious error condition which might interfere with regular operation and the database will be taken offline. If the error happened during upgrade of the ‘master’ database, it will prevent the entire SQL Server instance from starting. Examine the previous errorlog entries for errors, take the appropriate corrective actions and re-start the database so that the script upgrade steps run to completion.”

Cannot recover the master database. SQL Server is unable to run. Restore master from a full backup, repair it, or rebuild it. For more information about how to rebuild the master database, see SQL Server Books Online.

This is where i sh*t myself! After a quick trip i composed myself and decided to try a rebuild of the database. In SQL 2005 and SQL 2008 R2 i know its different that SQL 2000. To do a rebuild in SQL Server 2008 R2 i used the installation media ( you can use the local setup file which lives in C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2) and used the setup.exe file and ran the following command:


This ran successfuly (it didnt come up errors once it has run) but alas the same problem, so rebuilding the master database didnt work.

What did work for me was stopping the MSSQL service and starting it up again by using the below commands:

>cd “C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\”
>sqlservr.exe -c -m -s SQLinstance
>sqlcmd -S SERVERNAME,1433 -E

Now the switches on sqlserver allow it run not as a service (-c) and in single user mode (-m) and the -s allows you to specifiy the server name. Running SQL in single user mode means no-one can login normally and allows SQL to get on with its upgrade script in peace.

I left this to run for around 15 minutes (if its a busy SQL server you’ll see many attempts of other servers/workstations logging in. To stop this i just pulled the network plug as I was working locally. If you need to remote on don’t do tis…for obvious reasons :p) and after this finished and I can could see the upgrade script ran successfully I was able to start the SQL service up in the Services.msc and login OK using the SSMS. No need to re-run the patch or roll back and get screamed at by any developers (which could of been the case for me)

After this fault happened I now always allow SQL to start in single user mode after an update/upgrade so it can run these scripts peacefully. Its not really needed and its mainly me siding on the side of caution but it never hurts 🙂

Create new mail contacts from a CSV file for Exchange 2007/2010

Today I had a colleague come to me, asking for help as she had a user asking to have 649 mail contacts created and added to a distribution group by the end of the day.

Now instead of sitting there and slowly adding in each and every single contact individually (which if you’ve had to do this before in Exchange you’ll know it’s an absolute nightmare!!) I decided to modify a script I wrote a while back for importing mailboxes from a CSV file.

So the format of the CSV file should be:

Name Email OUPAth
Test User domain.local/Mail Contacts/Test

For the OUPath you can easily find this out by going into your Active Directory and right clicking on the folder you wish the mail contacts to be imported into, and going to Properties
OU Properties

As you can see in the Object section you can find out the OU Path, by looking at the Canonical name of object:

Once the .CSV file is created and formatted correctly you can use this wonderful little powershell script I wrote:

Import-CSV C:\createnewcontact.csv | ForEach-Object{
New-MailContact -ExternalEmailAddress $_.Email -Name $_.Name -OrganizationalUnit $_.OUpath

Now I’ll talk you through section by section on what this script does so you’re a little more aware (and i can prove I didn’t just copy and paste from a website :p)

Now “Import-CSV C:\createnewcontact.csv” basically tells Powershell to import data from the CSV file which lives directly on the C:\ and is called createnewcontact.csv (bare in mind if you call your CSV differently you will need to change this section)

“ForEach-Object”{ allows you to perform an action on each item in the collection (in this case everything between the { }

“New-MailContact” This is kind of self-explainatory to be honest. If you want a new mailbox you put in New-Mailbox and for a new mail contact you use New-MailContact

Now when you run New-MailContact manually into PowerShell it asks you for 2 pieces of information:

  • ExternalEmailAddress
  • Name

So when your PowerShell script runs New-MailContact it still needs this information. So by using “-ExternalEmailAddress$_.Email” you are telling the script that when it gets asks what the -ExternalEmailAddress is the PowerShell sees $_.Email which signifies to it that it should get this information from the Email column ($_. tells it to use the column and the name after it is the column name)

This is the same for -Name $_.Name -OrganizationalUnit $_.OUpath

I’m not the greatest at explaining things so I do apologise. If in doubt just copy exactly what I’ve done and you’ll be fine 🙂

Mailcontact Powershell

Pop in the location of the script into Power Shell (or if you’re really lazy just drag and drop the script from Explorer into the Power Shell window) and hit enter and watch it run away and create hundreds of mail contacts from your .CSV file in seconds…and then have a beer