📄 JScript (WSH)
Get Environment Variables Report (JScript)
Queries Win32_Environment via WMI and prints Environment Variables to the console — JScript, VBScript's WSH sibling language.
GetEnvironmentReport.js
// ============================================================
// GetEnvironmentReport.js
//
// Reports Environment Variables via WMI (Win32_Environment). JScript (Windows Script Host) —
// VBScript's sibling language, run the same way via cscript/wscript.
//
// Usage: cscript GetEnvironmentReport.js
// ============================================================
var objWMIService = GetObject("winmgmts:\\\\.\\root\\cimv2");
var colItems = objWMIService.ExecQuery("SELECT Name, VariableValue, UserName FROM Win32_Environment");
var e = new Enumerator(colItems);
var output = "";
var count = 0;
for (; !e.atEnd(); e.moveNext()) {
var item = e.item();
output += "Name: " + item.Name + "\n";
output += "VariableValue: " + item.VariableValue + "\n";
output += "UserName: " + item.UserName + "\n";
output += new Array(41).join("-") + "\n";
count++;
}
if (count === 0) {
WScript.Echo("No Environment Variables found.");
} else {
WScript.Echo(output);
}