Archive for the ‘How To: Exchange Management Shell’ Category

How To: Exchange Management Shell Entrants & Winner

October 11, 2006

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:\”

How To: Exchange Management Shell – entries – last call

October 6, 2006

Alright, everyone has been asking about the how to powershell contest, so let’s wrap it up! There have not been a lot of entries (although there have been some new ones lately). So get your entries in and tag it with “How To: Exchange Management Shell”

I will collect the list of entrants on Tuesday – which means there is only a few days left. After which I will randomly pick a winner out of the entrants I can find. I have to find them to count them!!

I recommend taking a look at Lee’s new book (I just started reading it myself) for some ideas on how to compose a good entry. Of course there are some good pointers on the wiki and around the blogosphere.Don’t forget the winner is randomly chosen and receives a signed copy of Bruce Payette’s book (Bruce is one of the creators of Powershell).

How To: Exchange Management Shell – entrants

September 14, 2006

Well I’m not sure about entries but the Exchange team had a great post…………. their one-liner was better then what I was doing

“1..<nn> | foreach {new-StorageGroup SG_$_ -server <server> | new-MailboxDatabase MBDB}”

Yet….there isn’t much from non-MS employees…… It is a little overbearing and certainly a new thing to learn in addition to the rest of the new infrastructure. Lee and Vivek……how about an EMS pocket guide?

Jeff still dedicated a signed copy of Bruce’s upcoming book…. if we get any non-MS entries it may be yours (I have almost finished the first chapter and have found it an easy, useful read so far).

Perhaps Rui will put together a special reading section of the best finds as well…

PowerShell Scripting for Exchange 2007

August 25, 2006

Vivek has been doing a lot of work to spread the word on the Exchange Management Shell and the wiki has A LOT of stuff as well (thanks to Vivek….go enjoy the best part of Seattle summer). I have noticed more people contributing to the effort of teaching the way of the shell and individual commands. This is all good as it takes some time to get used to the new format and nomenclature. Personally I am still a bit behind, there was the big warning on the beta 1 monad staid this is going to change by RTM so I didn’t do as much as I should have to learn it, of course it hasn’t changed that much but I am still behind :(

Today I saw Ben Winzenz’s great EMS post along with all the others and was inspired by ProBlogger‘s group writing project. So I would like to invite everyone to put up a post or comment on this post with a unique Exchange 2007 powershell script (sorry no prizes unless Manning Publications wants to sponsor it with a free copy of Bruce Payette‘s book). I have created a new tag that we can file them under so they will be easily searchable, “How To: Exchange Management Shell”. When your post is up, send me a link and I will combine all the posts that come in next week and post The List first thing in September

UPDATE 08/26 9:00am: Jeffrey Snover is willing to pitch in a signed copy of Bruce’s Book as a raffle type prize for this. If anyone else has a great prize, book, powershell shirt, etc, I will be happy to raffle them off to the list as well.   Again, to officially enter (now that there is a prize), send me an email with a link to your post josh . maher at gmail dot com OR put the link to your post as a comment to this entry. Oh and don’t forget the tag…..

Now we just need to get KC to convince the interns to stick around for another week and enter them into the wiki or the Exchange 2007 script repository so they will live on a little longer.

Wait!! where is my shell post? Mine will be a bit more brief then Ben’s but hopefully useful….

I do a lot of testing with different code releases and need to build and rebuild exchange servers a lot (too much already and the product isn’t even out yet!). Amazingly every time I rebuild my environment with a new drop of code I learn something new. One of those things I have been using for some time is a neat trick for creating multiple storage groups with the foreach command……

foreach (

$i in (3,4)

) {

new-storagegroup -name SG$i -server “E2k7-CCR-B2” -logfolderpath “C:\mounts\SG$i\Log” -SystemfolderPath “C:\mounts\SG$i\log”

}

foreach (

$i in (3,4)

) {

new-mailboxdatabase -storageGroup E2k7-CCR-B2\SG$i -Name MDB -edbFilePath “C:\mounts\SG$i\db\MDB.edb”

}

The first one will create 2 storage groups named SG3 & SG4. You can use this for up to 50 storage groups of course, but it was easier to show just two. The second one just takes those storage groups and creates databases inside of them. Usually I end up configuring my storage groups differently so it was easier to separate the commands…… If there is a better way to do this, please let me know….

Here is the screen shot of these in action!!

btw…. this is on VMWare Server :p

Digg this post Del.icio.us Furl