header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Check if exchange db exists
Last Post 10 Jan 2012 11:04 AM by MaryK. 7 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
MaryKUser is Offline
Basic Member
Basic Member
Posts:104
Avatar

--
10 Jan 2012 08:53 AM
    I need to check if an exchange database exists using get-mailboxdatabase. If it exists then do actionA if not do actionB. What's the quickest way?

    MaryKUser is Offline
    Basic Member
    Basic Member
    Posts:104
    Avatar

    --
    10 Jan 2012 09:05 AM
    Forgot to mention I am using this, but I need to suppress the error when the database is not found.


    $mailboxdatabase = (getmailboxdatabase mydatabase)
    if ($nailboxdatabase -eq $null)
    {
    Do actionA
    }
    else
    {
    Do ActionA
    }

    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    10 Jan 2012 09:14 AM
    Something like this:
     
    if (get-mailboxdatabase mydatabase -ea silentlycontinue){
        Write-Output "Found mydatabase"
    }
    else{
        Write-Output "mydatabase is not found"
    }
    


    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    MaryKUser is Offline
    Basic Member
    Basic Member
    Posts:104
    Avatar

    --
    10 Jan 2012 09:34 AM
    Thanks. I also found this while researching, which will do the same thing. 
    $mailboxdatabase = getmailboxdatabase mydatabase -Erroraction Silentlycontinue
    if (!$ailboxdatabasel)
    {
    Do actionA
    }
    else
    {
    Do ActionA
    }
    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    10 Jan 2012 09:50 AM
    You realize that you never use the variable "mailboxdatabase", you do use the null variable "$ailboxdatabasel", and in all cases, you do "ActionA", right? :)

    There is no need fo an intermediate variable to hold the results of the Get-MailboxDatabase call....

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    MaryKUser is Offline
    Basic Member
    Basic Member
    Posts:104
    Avatar

    --
    10 Jan 2012 09:54 AM

    A typo on my end: How does this look? It seems to be working on my end.

    $mailboxdatabase = getmailboxdatabase mydatabase -Erroraction Silentlycontinue
    if (!$mailboxdatabase)
    {
    Do actionA
    }
    else
    {
    Do ActionA
    }

    Karl MitschkeUser is Offline
    Basic Member
    Basic Member
    Posts:457
    Avatar

    --
    10 Jan 2012 10:52 AM
    Well, once again, either case runs "actionA" :)

    Karl
    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    MaryKUser is Offline
    Basic Member
    Basic Member
    Posts:104
    Avatar

    --
    10 Jan 2012 11:04 AM
    The sencond should be actionB which is correct in my envoronment. Thanks again.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer