Get User Status

howbs2002 111 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
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,455 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dillon Silzer 57,231 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.

    0 comments No comments

Your answer

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