Last active
May 21, 2019 19:29
-
-
Save eizedev/8d4e0b9b387396f49212abda9d7e6d1b to your computer and use it in GitHub Desktop.
Get all users on a linux operating system by parsing the /etc/passwd file
This file contains 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
$passwd = (Get-Content /etc/passwd).ForEach({ | |
$userfields = $_ -split ':' | |
return [pscustomobject]@{ | |
UserName = $UserFields[0] | |
ShadowFile = $(if ($userfields[1] -eq 'x') { $true }else { $false }) | |
UserId = $UserFields[2] | |
GroupId = $userfields[3] | |
FullName = $Userfields[4] | |
HomeDirectory = $UserFields[5] | |
ShellAccount = $Userfields[6] | |
} | |
}) | |
return $passwd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment