⚡ PowerShell 5.1+
Get Local User Accounts Report
Queries Win32_UserAccount via WMI and reports Local User Accounts in a formatted table, with an optional CSV export.
Get-UserAccountReport.ps1
<#
.SYNOPSIS
Reports Local User Accounts on this computer via WMI (Win32_UserAccount).
.DESCRIPTION
Queries Win32_UserAccount and displays Name, FullName, Disabled, Lockout, LocalAccount for each item found.
Use -ExportPath to also save the results to a CSV file.
.PARAMETER ExportPath
Optional path to a .csv file to write the results to.
.EXAMPLE
.\Get-UserAccountReport.ps1
.EXAMPLE
.\Get-UserAccountReport.ps1 -ExportPath C:\Reports\useraccount.csv
#>
[CmdletBinding()]
param(
[string]$ExportPath
)
$items = Get-CimInstance -ClassName Win32_UserAccount | Select-Object Name, FullName, Disabled, Lockout, LocalAccount
if (-not $items) {
Write-Host "No Local User Accounts found." -ForegroundColor Yellow
return
}
$items | Format-Table -AutoSize
if ($ExportPath) {
$items | Export-Csv -Path $ExportPath -NoTypeInformation -Encoding UTF8
Write-Host "`nExported to $ExportPath" -ForegroundColor Cyan
}