header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Select-Object and Expressions
Last Post 12 Aug 2010 08:18 AM by Ayth. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
AythUser is Offline
Basic Member
Basic Member
Posts:232
Avatar

--
12 Aug 2010 07:53 AM
    Hello All,

    Had a recent request from a colleague to pull some information out of Exchange. He wanted the following information:

    Username, Mailbox Database, OU, Company, CustomAttribute1

    I originally wanted to do it as a one-liner so that the person could run it at leisure, so started looking at expressions, since Get-Mailbox doesn't give the Company or OrganizationalUnit properties. But ran into an issue I was wondering if I can get help on. I started out as so:

    Get-Mailbox | Select-Object Name,Database,@{Name="Company";Expression={Get-User -Identity $_.samAccountName | Select-Object Company}}

    Problem is the output ended up being like so:

    Name Database Company
    ---- -------- -------
    Darrin Henshaw HFXIGNEXMB1\HFX\HFX @{Company=Ignition}

    Note the formatting of the company field. I didn't play around with it too much, and ended up building a small script using custom objects to pull the info, but wanted to know for future how I do this. Thanks.
    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    AythUser is Offline
    Basic Member
    Basic Member
    Posts:232
    Avatar

    --
    12 Aug 2010 08:18 AM
    Nice I feel like an idiot now, I just hit post then figure it out. This works:

    Get-Mailbox | Select-Object Name,Database,@{Name="Company";Expression={(Get-User -Identity $_.samAccountName).Company}}


    My Blog about Powershell http://poweroftheshell.blogspot.com/ Follow me on twitter @darrinhenshaw
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer