0

I'am not able to get any results of the Exchange Management CmdLet (OnPremises) Get-MailboxDatabaseCopyStatus within a Function or Expression.

function Get-DAGDatabaseCopys ($Identity) {
   # Neither this line:
   #[Int]$DBCopys = Invoke-Command { @(Get-MailboxDatabaseCopyStatus -Identity $Identity).count }
   # Or this line works:
   $DBCopys = @(Get-MailboxDatabaseCopyStatus -Identity $Identity).count
   return $DBCopys
}

Usage:

Get-DAGDatabaseCopys -Identity "DatabaseName"

Expression Example:

$strMasterType = "DatabaseAvailabilityGroup"
$expDatabaseSpaceGB   = @{Expression={if(($_.MasterType -eq $strMasterType) -and ($IncludeDagCopys)){
    start-sleep 1 
    $DBCopys = @(Get-MailboxDatabaseCopyStatus -Identity $_).count
    return [math]::Round((Value-ToGB -Value $_.AvailableNewMailboxSpace),2) * $DBCopys
};Label="DatabaseWhiteSpaceSizeGB"}

Usage:

$MailboxDBStatus      = Get-MailboxDatabase -Status | select ServerName, Name, MasterType, $expDatabaseSpaceGB

The Returnvalue of the function or expression will always be empty or 0 (if DataType is Int). There is no data in the $DBCopys Object within the function/expression, even if i try to receive the full object (not just the count).

The Same CmdLet direct in the Script Root or on the Powershell Console work's as expected.

Is this a general behaviour of this cmdlet or am I doing something wrong here?

Thx.

Michael
  • 1
  • 2

2 Answers2

0

Based on my knowledge and test, the AvailableNewMailboxSpace parameter is only used for the Get-MailboxDatabase cmdlet rather than Get-MailboxDatabaseCopyStatus cmdlet: enter image description here

Do you want to get the value of the AvailableNewMailboxSpace parameter or the free space of your disk(DiskFreeSpace)? enter image description here

If it's the former, I think you need replace the Get-MailboxDatabaseCopyStatus cmdlet with the Get-MailboxDatabase -Status cmdlet. If it's the latter, replace the AvailableNewMailboxSpace cmdlet with the DiskFreeSpace cmdlet.

Besides, the cmdlet Value-ToGB -Value seems not be supported by PowerShell, I think you could try using the following command:

return [math]::Round(($_.AvailableNewMailboxSpace)/1GB,2) * $DBCopys
Ivan_Wang
  • 1,333
  • 1
  • 4
  • 4
  • The goal was to get the number of MBX Copys and multiply it with the available Database Copy within an expression for billing related calculations. The cmdlets are working as expected within a function or in the script root. The problem only occurs within inline powershell expressions. So i solved it by avoiding the inline expressions. 'Value-ToGB -Value' is a custom function which does exactly the same as your math code example. Thanks for your help and sorry for the long delay. That was for personal reasons. – Michael Feb 26 '21 at 20:07
0

The cmdlets are working as expected within a function or in the script root. The problem only occurs within inline powershell expressions. So i solved it by avoiding the inline expressions.

Michael
  • 1
  • 2