⚡ PowerShell 5.1+

Get Local Groups Report

Queries Win32_Group via WMI and reports Local Groups in a formatted table, with an optional CSV export.

By WindowsScripting.com · 860 B
Get-GroupReport.ps1
<#
.SYNOPSIS
    Reports Local Groups on this computer via WMI (Win32_Group).

.DESCRIPTION
    Queries Win32_Group and displays Name, Description, Domain 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-GroupReport.ps1

.EXAMPLE
    .\Get-GroupReport.ps1 -ExportPath C:\Reports\group.csv
#>

[CmdletBinding()]
param(
    [string]$ExportPath
)

$items = Get-CimInstance -ClassName Win32_Group | Select-Object Name, Description, Domain

if (-not $items) {
    Write-Host "No Local Groups 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
}