Skip to content

Instantly share code, notes, and snippets.

@emrekgn
Last active October 9, 2017 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrekgn/e0423267077860560fa192055c81b973 to your computer and use it in GitHub Desktop.
Save emrekgn/e0423267077860560fa192055c81b973 to your computer and use it in GitHub Desktop.
Powershell Tricks - List Users with groups, home directory and disabled status
#
# Prints user name, groups, home directory and disabled status
#
$adsi = [ADSI]"WinNT://$env:COMPUTERNAME"
$adsi.Children | where { $_.SchemaClassName -eq 'user' } | Foreach-Object {
$groups = $_.Groups() | Foreach-Object {
$_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)
}
$user = Get-WmiObject Win32_UserAccount -filter "LocalAccount=True AND Name='$($_.Name)'"
$userprofile = Get-WmiObject Win32_UserProfile -filter "SID='$($user.SID)'"
$_ | Select-Object @{n='UserName';e={$_.Name}},
@{n='Groups';e={$groups -join ','}},
@{n='HomeDirectory';e={$userprofile.LocalPath}},
@{n='Enabled';e={-not $user.disabled }}
} | Format-Table -autosize -wrap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment