Skip to content

Instantly share code, notes, and snippets.

@eizedev
Last active May 21, 2019 19:29
Show Gist options
  • Save eizedev/8d4e0b9b387396f49212abda9d7e6d1b to your computer and use it in GitHub Desktop.
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
$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