Calling hash Table inside Calculated property issue?

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
Posts: 210
Joined: Wed Oct 12, 2011 10:52 am

Calling hash Table inside Calculated property issue?

Post by ITEngineer »

Hi Folks,

I need some help to fix the one line which maps the values of a number to a string in this Hashtable.

Code: Select all

$mailboxType = @{
    "0"               = "UserMailbox"
    "1073741824"   = "Shared Mailbox"
    "6"               = "MailUser"
    "7"               = "Room"
    "8"               = "Equipment"
    "-2147483642"  = "RemoteUserMailbox"
    "-1073741818 " = "RemoteUserMailbox-Hybrid Delegate"

Get-MsolUser -All |
Where-Object { ($_.blockcredential -eq $true) -and ($_.isLicensed -eq $true) } |
Select-Object DisplayName,
              @{ n = 'Mailbox Type'; e = { $mailboxType[$_.CloudExchangeRecipientDisplayType].GetEnumerator().Value.ToString() } },
              WhenCreated | Format-Table -AutoSize
The script is working fine it is just the Hashtable calling is not working.

The problem is the column Mailbox Type is always empty. But when I just use the default CloudExchangeRecipientDisplayType, the column value is a meaningless decimal number like in ... directory/

Thank you in advance
/* IT Engineer */