Script to retrieve all local user accounts information on remote computers (PowerShell)

Introduction

This PowerShell Script shows how to retrieve all local user accounts information on remote computers.

Scenarios

An enterprise uses Active Directory to manage users and groups, but still need to manage local user accounts. This might be because the computer is not a domain member (if it is in a perimeter network). This script allows admins to retrieve all local user accounts information to management on remote computers, it will be really useful.

Script

Step1: Start the PowerShell Console with administrator. To run the script in the Windows PowerShell Console, type the command< Script Path> at the Windows PowerShell Console.

For example, you can type the command Get-Help C:\Script\GetLocalAccount.ps1 -Full to display the entire help file for this function, such as the syntax, parameters, or examples. This is shown in the following figure.

Example

Example 1: Type the C:\Script\GetLocalAccount.ps1 command in the Windows PowerShell Console. It shows how to list all local users on local computer. 
  

Here are some code snippets for your references.

PowerShell
Edit|Remove
If($Credential) 
{ 
    $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" ` 
    -Filter "LocalAccount='$True'" -ComputerName $Computer -Credential $Credential -ErrorAction Stop 
}else{ 
    $AllLocalAccounts = Get-WmiObject -Class Win32_UserAccount -Namespace "root\cimv2" ` 
    -Filter "LocalAccount='$True'" -ComputerName $Computer -ErrorAction Stop 
}

Prerequisite

Windows PowerShell 2.0

Additional Resources

Get-WmiObject

Related forum threads:
http://social.technet.microsoft.com/Forums/en-US/winservermanager/thread/31eeea8c-e268-4dd0-8a62-4fc44e87f3a2 
http://powershellcommunity.org/Forums/tabid/54/aft/3954/Default.aspx 
http://www.autoitscript.com/forum/topic/90588-list-local-user-accounts/