SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-104621%22%20slang%3D%22en-US%22%3EExchange%20Management%20Shell%3A%20Getting%20title%20in%20Get-Mailbox%20for%20all%20results%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-104621%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20get%20a%20list%20of%20mailboxes%20that%20have%20been%20hidden%20from%20the%20GAL.%3CBR%20%2F%3EThe%20results%20have%20the%20contain%20there%20name%2C%20a%20true%20or%20false%20for%26nbsp%3BHiddenFromAddressListsEnabled%20and%20there%20(job)title.%3CBR%20%2F%3EThe%20problem%20is%20that%20the%20title%20can%20only%20be%20called%20with%20Get-User.%20I%20found%20how%20to%20combine%20the%20two.%26nbsp%3B%3CBR%20%2F%3EBut%20the%20result%20only%20show%20the%20Title%20on%20the%20last%20result.%3CBR%20%2F%3E%3CBR%20%2F%3ESofar%20i%20have%20this.%20For%20testing%20limited%20to%2010%3C%2FP%3E%3CPRE%3EGet-Mailbox%20-ResultSize%2010%20%7C%20Select%20Name%2CHiddenFromAddressListsEnabled%2C%20%40%7Bn%3D%22Title%22%3Be%3D%7B(get-user%20%24_.name).title%20%7D%7D%3C%2FPRE%3E%3CP%3EIm%20problably%20missing%20something%20really%20simple%20here%20but%20i%20cant%20see%20it.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-104621%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3E2010%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExchange%20Server%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-104988%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20Management%20Shell%3A%20Getting%20title%20in%20Get-Mailbox%20for%20all%20results%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-104988%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20seems%20to%20work%20sofar%2C%20thanks.%3CBR%20%2F%3ETitle%20can%20indeed%20be%20empty%2C%20but%20in%20our%20situation%20that%20will%20only%20happen%20with%20very%20few%20mailboxes.%3CBR%20%2F%3EThanks%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-104788%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20Management%20Shell%3A%20Getting%20title%20in%20Get-Mailbox%20for%20all%20results%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-104788%22%20slang%3D%22en-US%22%3E%3CP%3EI%20think%26nbsp%3Byou%20are%20using%20old%20version%20of%20powershell%20(2.0)%20so%20that%20you%20got%20in-correct%20result%26nbsp%3Band%20%22name%22%20is%20also%20%26nbsp%3Bunique%20value%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20I%20have%20modified%20the%20script%20and%20this%20script%20will%20work%20for%20all%20the%20powershell%20version.%3C%2FP%3E%3CPRE%3E%24users%20%3D%20Get-Mailbox%20-ResultSize%2010%20%7C%20Select%20Name%2CHiddenFromAddressListsEnabled%0A%24users%20%7C%20Foreach-Object%7B%0A%0A%24userinfo%3DGet-user%20%24_.name%20%7Cselect%20Title%0ANew-Object%20-TypeName%20PSObject%20-Property%20%40%7B%0A%20%20%20%20%20%20Name%20%3D%20%24_.Name%0A%20%20%20%20%20%20HiddenFromAddressListsEnabled%20%3D%24_.HiddenFromAddressListsEnabled%0A%20%20%20%20%20%20Title%3D%20%24userinfo.Title%0A%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%7D%0A%0A%7D%20%7Cselect%20Name%2CHiddenFromAddressListsEnabled%2CTitle%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-104675%22%20slang%3D%22en-US%22%3ERe%3A%20Exchange%20Management%20Shell%3A%20Getting%20title%20in%20Get-Mailbox%20for%20all%20results%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-104675%22%20slang%3D%22en-US%22%3E%3CP%3EDon't%20use%20the%20Name%20property%2C%20or%20any%20other%20property%20that%20is%20not%20unique%20-%20you%20will%20get%20incomplete%2Fbroken%20set%20of%20results.%20Also%2C%20remember%20that%20Title%20is%20not%20a%20mandatory%20attribute%20and%20can%20be%20empty.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnyway%2C%20your%20example%20works%20fine%2C%20I%20just%20adjusted%20it%20to%20use%20the%20UPN%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGet-Mailbox%20-ResultSize%2010%20%7C%20Select%20Name%2CHiddenFromAddressListsEnabled%2C%20%40%7Bn%3D%22Title%22%3Be%3D%7B(Get-User%20%24_.UserPrincipalName).title%20%7D%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

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.

3 Replies

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 }}

 

 

best response confirmed by Mark van Hasseld (New Contributor)
Solution

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

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