Find Local Users

by Jul 21, 2011

On Windows 7, the easiest way to find local user accounts is to use net.exe. Here is a simple PowerShell wrapper called Get-LocalUser:

function Get-LocalUser {
 $users = net user
 $users[4..($users.count-3)] -split '\s+' | Where-Object { $_ }
}

It returns a list of local users, and you can use all the PowerShell comparison operators. This will check whether a local account "Tobias" exists:

PS> (Get-LocalUser) -contains 'Tobias'

And this line will return all local accounts that contain "test":

PS> (Get-LocalUser) -like '*test*'

 

Twitter This Tip!
ReTweet this Tip!