⚡ PowerShell 5.1+
Get Environment Variables Report
Queries Win32_Environment via WMI and reports Environment Variables in a formatted table, with an optional CSV export.
Get-EnvironmentReport.ps1
<#
.SYNOPSIS
Reports Environment Variables on this computer via WMI (Win32_Environment).
.DESCRIPTION
Queries Win32_Environment and displays Name, VariableValue, UserName 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-EnvironmentReport.ps1
.EXAMPLE
.\Get-EnvironmentReport.ps1 -ExportPath C:\Reports\environment.csv
#>
[CmdletBinding()]
param(
[string]$ExportPath
)
$items = Get-CimInstance -ClassName Win32_Environment | Select-Object Name, VariableValue, UserName
if (-not $items) {
Write-Host "No Environment Variables 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
}