Link to home
Start Free TrialLog in
Avatar of Gary Dewrell
Gary DewrellFlag for United States of America

asked on

Need help with exchange powershell script

I am working on a script that will write to the event log a error when my exchange 2010 database is not mounted on the prefered server. Here is the function I have written to check if the databvase is "Mounted" on the prefered server.

I added a write-output to check that my $Mounted is getting the proper result and it is but the function is always returning false.

function IsDatabaseMounted
{
      $Mounted = Get-MailboxDatabaseCopyStatus "MBX01\sever1" | fl status
      write-output $Mounted
      if ($Mounted  -eq "Status : Mounted"){
      
            return $true;
            
      }else{
            return $false
      }      
}
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary Dewrell

ASKER

If your saying replace

 if ($Mounted  -eq "Status : Mounted"){

with

if ($Mounted.Status -eq  "Status : Mounted"){

That did not work.
Ah but you did point me in the correct direction.
The below worked.


function IsDatabaseMounted
{
      $Mounted = Get-MailboxDatabaseCopyStatus "PDI-Temple-MBX01\server1"
      write-output $Mounted.status
      if ($Mounted.status -eq "Mounted"){
      
            return $true;
            write-output "TRUE!!!!!"

      }else{
            return $false
      }      
}
Not the whole answer but you got me pointed int the right direction. Thanks!
remove the fl status:


function IsDatabaseMounted
{
      $Mounted = Get-MailboxDatabaseCopyStatus "MBX01\sever1" 
      
      if ($Mounted.Status  -eq "Mounted"){
      
            return $true;
            
      }else{
            return $false
      }      
}

Open in new window

you were ahead of me... as long as you got it working :)