How To: Exchange Management Shell Entrants & Winner

Well not many more entrants that came out of the woodwork….

Bharat Suneja posted a nice entry since the last call….

But the winner is Nick Smith!! who posted this handy dandy little script to the comments of the original post.

Jeffrey, I heard Bruce’s book is almost done, will you be able to get Nick a copy still?

  1. Here is a script to dynamically detect all databases on an Exchange 2007 server and backup each database with ntbackup.

    function perform_backup ([string] $ServerName, [string] $BackupRootDrive) {
    $BackupScriptPath = $BackupRootDrive + “BackupScripts\”
    $BackupPath = $BackupRootDrive + “DailyBackups\”

    $BackupScript = $BackupScriptPath + $ServerName + “BackupScript.bat”
    $BackupLog = $BackupScriptPath + “ExchangeBackupLogs.log”
    new-item $BackupScript -type file -force
    new-item $BackupLog -type file -force

    Add-Content $BackupScript “@ECHO off”
    #Add registry keys to improve ntbackup performance
    #See http://www.microsoft.com/technet/itsolutions/msit/operations/exchbkup.mspx
    Add-Content $BackupScript “reg add `”HKCU\Software\Microsoft\Ntbackup\Backup Engine`” /v `”Logical Disk Buffer Size`” /t REG_SZ /d 64 /f”
    Add-Content $BackupScript “reg add `”HKCU\Software\Microsoft\Ntbackup\Backup Engine`” /v `”Max Buffer Size`” /t REG_SZ /d 1024 /f”
    Add-Content $BackupScript “reg add `”HKCU\Software\Microsoft\Ntbackup\Backup Engine`” /v `”Max Num Tape Buffers`” /t REG_SZ /d 16 /f”

    Get-MailboxDatabase | where {$_.ServerName -eq $ServerName} | foreach{
    $JetBackupSyntax = “JET ” + $_.ServerName + “\Microsoft Information Store\” + $_.StorageGroupName + “\” + $_.AdminDisplayName
    $BksFileName = $BackupScriptPath + $_.ServerName + “” + $_.StorageGroupName + “” + $_.AdminDisplayName + “.bks”
    $JetBackupSyntax | out-file -filepath $BksFileName -encoding unicode
    Add-Content $BksFileName “”
    $BksDescriptiveName = $_.ServerName + “_” + $_.StorageGroupName + “_” + $_.AdminDisplayName
    $NTBackupLine = “C:\WINDOWS\system32\ntbackup.exe backup `”@” + $BksFileName + “`” /n `”” + $BksDescriptiveName + “`” /d `”” + $BksDescriptiveName + “`” /v:no /r:no /rs:no /hc:off /m normal /fu /j `”” + $BksDescriptiveName + “`” /l:s /f `”” + $BackupPath + $BksDescriptiveName + “.bkf`” ”
    Add-Content $BackupScript $NTBackupLine
    }
    Get-PublicFolderDatabase | where {$_.ServerName -eq $ServerName} | foreach{
    $JetBackupSyntax = “JET ” + $_.ServerName + “\Microsoft Information Store\” + $_.StorageGroupName + “\” + $_.AdminDisplayName
    $BksFileName = $BackupScriptPath + $_.ServerName + “” + $_.StorageGroupName + “” + $_.AdminDisplayName + “.bks”
    $JetBackupSyntax | out-file -filepath $BksFileName -encoding unicode
    Add-Content $BksFileName “”
    $BksDescriptiveName = $_.ServerName + “_” + $_.StorageGroupName + “_” + $_.AdminDisplayName
    $NTBackupLine = “C:\WINDOWS\system32\ntbackup.exe backup `”@” + $BksFileName + “`” /n `”” + $BksDescriptiveName + “`” /d `”” + $BksDescriptiveName + “`” /v:no /r:no /rs:no /hc:off /m normal /fu /j `”” + $BksDescriptiveName + “`” /l:s /f `”” + $BackupPath + $BksDescriptiveName + “.bkf`” ”
    Add-Content $BackupScript $NTBackupLine
    }
    & $BackupScript
    }

    perform_backup “ServerName” “R:\”

About these ads

5 Responses to “How To: Exchange Management Shell Entrants & Winner”

  1. Vivek Says:

    Hey there, I’ll keep up my end—entries from my blog, and the ninjas site are forthcoming to announce the winner :) ehlo blog takes time, but I will also do that at the same time we announce the winner for the official MS contest.

    Congratulations Nick and nice work to the rest of the entries. Can’t wait to see more.

  2. Bruce Payette Says:

    Hi Josh,

    I’ve talked to Manning and we’re going to arrange for Nick to get a copy of the book along with on-line access through the Manning early access program. Send me an email and we’ll get everything set up. Thanks.

    -bruce
    =================================================
    Bruce Payette [MSFT]
    Technical Lead, Windows PowerShell

  3. Blogs, Blogs, and more blogs « Messaging….. Technology…… Life….. Says:

    [...] old co-worker of mine from the startup days Marcel started blogging, as did the powershell contest winner Nick. Of course Nick is keeping us up to speed with lots of new scripts and tips for you [...]

  4. Bill Compton Says:

    Hi Jim. Photos i received. Thanks

  5. Exchange 2007 Book Give Away!! « Messaging….. Technology…… Life….. Says:

    [...] suggestions on how to give these things away. I previously partnered with Manning press to do the powershell script contest which was fun, but what else would be interesting for a giveaway? Post your ideas in the comments [...]

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: