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.