Forum Discussion

JoSoFine's avatar
JoSoFine
Copper Contributor
Sep 08, 2017
Solved

Exchange Management Shell: Getting title in Get-Mailbox for all results

I am trying to get a list of mailboxes that have been hidden from the GAL.
The results have the contain there name, a true or false for HiddenFromAddressListsEnabled and there (job)title.
The problem is that the title can only be called with Get-User. I found how to combine the two. 
But the result only show the Title on the last result.

Sofar i have this. For testing limited to 10

Get-Mailbox -ResultSize 10 | Select Name,HiddenFromAddressListsEnabled, @{n="Title";e={(get-user $_.name).title }}

Im problably missing something really simple here but i cant see it.

  • I think you are using old version of powershell (2.0) so that you got in-correct result and "name" is also  unique value 

    Here I have modified the script and this script will work for all the powershell version.

    $users = Get-Mailbox -ResultSize 10 | Select Name,HiddenFromAddressListsEnabled
    $users | Foreach-Object{
    
    $userinfo=Get-user $_.name |select Title
    New-Object -TypeName PSObject -Property @{
          Name = $_.Name
          HiddenFromAddressListsEnabled =$_.HiddenFromAddressListsEnabled
          Title= $userinfo.Title
               
          }
    
    } |select Name,HiddenFromAddressListsEnabled,Title

3 Replies

  • I think you are using old version of powershell (2.0) so that you got in-correct result and "name" is also  unique value 

    Here I have modified the script and this script will work for all the powershell version.

    $users = Get-Mailbox -ResultSize 10 | Select Name,HiddenFromAddressListsEnabled
    $users | Foreach-Object{
    
    $userinfo=Get-user $_.name |select Title
    New-Object -TypeName PSObject -Property @{
          Name = $_.Name
          HiddenFromAddressListsEnabled =$_.HiddenFromAddressListsEnabled
          Title= $userinfo.Title
               
          }
    
    } |select Name,HiddenFromAddressListsEnabled,Title
  • Don't use the Name property, or any other property that is not unique - you will get incomplete/broken set of results. Also, remember that Title is not a mandatory attribute and can be empty.

     

    Anyway, your example works fine, I just adjusted it to use the UPN:

     

    Get-Mailbox -ResultSize 10 | Select Name,HiddenFromAddressListsEnabled, @{n="Title";e={(Get-User $_.UserPrincipalName).title }}

     

     

    • JoSoFine's avatar
      JoSoFine
      Copper Contributor

      This seems to work sofar, thanks.
      Title can indeed be empty, but in our situation that will only happen with very few mailboxes.
      Thanks you