David Strome's Blog

A Microsofty's ramblings on Exchange Server and other stuff.

Exchange Server 2007 Cmdlet Examples

Exchange Server 2007 Cmdlet Examples

  • Comments 3
  • Likes

If you're new to Windows PowerShell and Exchange Server 2007, take a look at this link: http://www.microsoft.com/technet/scriptcenter/scripts/message/exch2007/default.mspx?mfr=true. The link goes to the Exchange Server 2007 Script Repository which contains a few dozen cmdlet and script examples for common administrative tasks. It's a really useful resource if you're just getting started.

Take a look and if you have any suggestions for examples we should add, be sure to send me a note via the Email page or post a comment.

Comments
  • Outlook 2007: Sync error 0x80190194 (OAB synchronization) Single Instance Storage Exchange when moving

  • I am trying to run a script which would give me a listing of the mailbox database size for each database on the one exchange server i have. The script is listed below.  I copied it from somewhere but can not make it work.  Error from running it follows.  Can anyone suggest a way that will work?

    $server = "NHCLUEXCH01"

    $exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.major -eq 8 -and $_.IsMailboxServer -eq $true } foreach ($server in $exchangeservers)

    {

       $db = Get-MailboxDatabase -server $server

       foreach ($objItem in $db)

       {

       $edbfilepath = $objItem.edbfilepath

       $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)

       $dbsize = Get-ChildItem $path

       $ReturnedObj = New-Object PSObject

       $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity

       $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))

       Write-Output $ReturnedObj

       }

    }

    -----------------------------

    [PS] C:\>$server = "NHCLUEXCH01"

    [PS] C:\>$exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayver

    sion.major -eq 8 -and $_.IsMailboxServer -eq $true } foreach ($server in $exchan

    geservers)

    Unexpected token 'in' in expression or statement.

    At line:1 char:144

    + $exchangeservers = Get-ExchangeServer |where-object {$_.admindisplayversion.m

    ajor -eq 8 -and $_.IsMailboxServer -eq $true } foreach ($server in  <<<< $excha

    ngeservers)

    [PS] C:\>

    [PS] C:\>{

    >>     $db = Get-MailboxDatabase -server $server

    >>     foreach ($objItem in $db)

    >>     {

    >>     $edbfilepath = $objItem.edbfilepath

    >>     $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1

    ).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)

    >>     $dbsize = Get-ChildItem $path

    >>     $ReturnedObj = New-Object PSObject

    >>     $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Databas

    e" -Value $objItem.Identity

    >>     $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}"

    -f ($dbsize.Length/1024KB))

    >>     Write-Output $ReturnedObj

    >>     }

    >> }

    >>

  • hi Kevin.

    The following should work for you. Since you're only interested in the one server, you don't need to retrieve the collection of servers (populating the $ExchangeServers variable). You just need to specify the server in the $Server variable you've already done.

    $server = "NHCLUEXCH01"

    $db = Get-MailboxDatabase -server $server

    foreach ($objItem in $db)

    {

    $edbfilepath = $objItem.edbfilepath

    $path = "`\`\" + $server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2)

    $dbsize = Get-ChildItem $path

    $ReturnedObj = New-Object PSObject

    $ReturnedObj | Add-Member NoteProperty -Name "Server\StorageGroup\Database" -Value $objItem.Identity

    $ReturnedObj | Add-Member NoteProperty -Name "Size (MB)" -Value ("{0:n2}" -f ($dbsize.Length/1024KB))

    Write-Output $ReturnedObj

    }

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment