none
Using select-object to output boolean type RRS feed

  • Question

  • Hi,

    I'm trying to list all user accounts on an AD group and export it to a CSV (I'll ignore this last part from now on as it's not relevant to the problem at hand). I want to list the "Name", "SamAccountName", and "Enabled" user properties, all of which are returned by the Get-ADGroupMember commandlet. The issue is the Enabled property (which is a Boolean type) is appearing blank on the output:

    PS C:\Users\testadmin> Get-ADGroupMember -identity "Domain Admins" | Where-Object { $_.objectClass -eq 'user' } | select-object Name,SamAccountName,Enabled

    Name                       SamAccountName             Enabled
    ----                          --------------                     -------
    Test admin                testadmin
    Test User                  testuser

    What am I missing?

    Thanks in advance.


    This post reflects my opinion on this specific thread. It does not necessarily represent my employer's opinion.

    SharePoint Consultant
    MCSA Windows Server 2008
    MCTS SharePoint 2010, Configuring



    Thursday, October 8, 2015 9:37 AM

Answers

  • The 'get-adgroupmember' cmdlet doesn't return the users object status. You have to execute 'get-aduser' to return the status, like this. Note the expression command in the select statement at the end.

    Get-ADGroupMember -identity "Domain Admins" | Where-Object { $_.objectClass -eq 'user' } | select-object Name,SamAccountName,@{Name="Enabled";Expression={(get-aduser $_).enabled}}

    Cheers,

    Ruud

    Blog: http://www.ruudborst.nl  Twitter:   LinkedIn:   

    Note: Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.




    Thursday, October 8, 2015 12:28 PM

All replies

  • The 'get-adgroupmember' cmdlet doesn't return the users object status. You have to execute 'get-aduser' to return the status, like this. Note the expression command in the select statement at the end.

    Get-ADGroupMember -identity "Domain Admins" | Where-Object { $_.objectClass -eq 'user' } | select-object Name,SamAccountName,@{Name="Enabled";Expression={(get-aduser $_).enabled}}

    Cheers,

    Ruud

    Blog: http://www.ruudborst.nl  Twitter:   LinkedIn:   

    Note: Please “Vote As Helpful” if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.




    Thursday, October 8, 2015 12:28 PM
  • Was just going to update to say the below worked (which is basically running the select on the user object instead as you suggested):

    Get-ADGroupMember -identity "Domain Admins" | Where-Object { $_.objectClass -eq 'user' } | Get-ADUser | select-object Name,SamAccountName,Enabled

    That would also work so I marked it as an answer, thanks Ruud.


    This post reflects my opinion on this specific thread. It does not necessarily represent my employer's opinion.

    SharePoint Consultant
    MCSA Windows Server 2008
    MCTS SharePoint 2010, Configuring



    Thursday, October 8, 2015 12:45 PM