Last active
October 9, 2017 11:06
-
-
Save emrekgn/e0423267077860560fa192055c81b973 to your computer and use it in GitHub Desktop.
Powershell Tricks - List Users with groups, home directory and disabled status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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