PowerShell List Local Accounts

<#  
    .SYNOPSIS
        Check List of Local Accounts on Systems 
    
    .DESCRIPTION
    Script queries AD for active computer objects and then checks for WinRM access.        
        If the WinRM access is successful then it pulls a list of local user accounts for each machine.
        This will then export results for validation of accounts. 
    
    .NOTES 
          Requires Active Directory Module
          Requires Rights on Machines   
          Author: Scott Head
          Min PSVer: Powershell 2.0
          Version: 1.0 (5/30/2019) Script Created             
#>


#Get List of Computers
$MyComputers=Get-ADComputer -filter * -Properties * | Where{($_.Enabled -eq $True) -and ($_.Operatingsystem -like "Windows*")} | Select -ExpandProperty Name 

#Instantiate Array
$MyArray=@()


#Check Access for Each Computers 
Foreach($Comp in $MyComputers){

    If((Invoke-Command -ErrorAction SilentlyContinue –ComputerName $comp –ScriptBlock {1}) –eq 1){
        $MyArray+=$Comp
    }
}
      
#Local Account Listing 
$MyCommand={
   Get-WmiObject -Class Win32_UserAccount -Filter  {LocalAccount='True' and Disabled='False'} | Select Caption
    
}


#Excution of Local Account Lookup     
Invoke-Command $MyArray -ScriptBlock $MyCommand | Export-CSV C:\temp\LocalAccounts.csv -Append -NoTypeInformation

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator