Gary Dewrell
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-MailboxDatabaseCopySta tus "MBX01\sever1" | fl status
write-output $Mounted
if ($Mounted -eq "Status : Mounted"){
return $true;
}else{
return $false
}
}
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-MailboxDatabaseCopySta
write-output $Mounted
if ($Mounted -eq "Status : Mounted"){
return $true;
}else{
return $false
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ah but you did point me in the correct direction.
The below worked.
function IsDatabaseMounted
{
$Mounted = Get-MailboxDatabaseCopySta tus "PDI-Temple-MBX01\server1"
write-output $Mounted.status
if ($Mounted.status -eq "Mounted"){
return $true;
write-output "TRUE!!!!!"
}else{
return $false
}
}
The below worked.
function IsDatabaseMounted
{
$Mounted = Get-MailboxDatabaseCopySta
write-output $Mounted.status
if ($Mounted.status -eq "Mounted"){
return $true;
write-output "TRUE!!!!!"
}else{
return $false
}
}
ASKER
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
}
}
you were ahead of me... as long as you got it working :)
ASKER
if ($Mounted -eq "Status : Mounted"){
with
if ($Mounted.Status -eq "Status : Mounted"){
That did not work.