Skip to content

Instantly share code, notes, and snippets.

@emrekgn
Last active Oct 9, 2017
Embed
What would you like to do?
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