Get User Status

howbs2002 116 Reputation points
2023-03-21T00:00:26.6466667+00:00

I am running this script which imports a list of AD groups, then gets users from each group, and gives me user info.

The export is good, except that the Enabled status column is empty.
Please help me figure out what I am missing, thank you.

Get-content C:\Temp\GroupList.txt |
	ForEach-Object{
		$groupname = $_
		Get-ADGroupMember $groupname -Recursive |
		Where-Object{ $_.objectClass -eq 'User' } |
		Select-Object *, @{ n = 'GroupName'; e = { $groupname } }
	} |
	Select-Object -Property GroupName,Name,samAccountName,Enabled | 
	Export-csv "C:\Temp\GroupMembers.csv" -NoTypeInformation
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

1 answer

Sort by: Most helpful
  1. Dillon Silzer 60,931 Reputation points
    2023-03-21T02:58:16.4966667+00:00

    Hello,

    I think you may need to make two different queries:

    Example

    Enabled:

    Get-Aduser -Filter 'Enabled -eq $true' -Properties *|select SamAccountName  |export-csv C:\outputEnabled.csv
    

    Disabled:

    Get-Aduser -Filter 'Enabled -eq $false' -Properties *|select SamAccountName |export-csv C:\outputDisabled.csv
    

    Incorporate that filter into your script and you should be set.

    Cited from https://social.technet.microsoft.com/Forums/ie/en-US/c96bbab7-fa79-41dc-9497-663c6d1b1781/getaduser-enabled-and-disabled-usersand-null-users?forum=winserverDS


    If this is helpful please accept answer.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.