Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions Links


SQL Server DBA Jobs

SQL Server – Windows Environment Variables and Powershell

29 August,2012 by Tom Collins

Powershell allows you to access the Windows Environment Variables. This is very useful in collecting system information . I’ve applied this technique in  creating an inventory report or troubleshooting a server issue. The purpose of Environment variables is to set values  at the OS level – that will impact processes. Accessing and reporting on the variables quickly can assist in maintaining server uptime.

A straightforward way of accessing all the environment variables is to use  “Dir env:\”  . A full list of environment variables will appear.  Although the full list appears , it requires some string manipulation to isolate one variable and value. Powershell allows you to access the individual Environment variables .

When scripting , there is a requirement to access the environment variables individually. To access individually use  $env  followed by the Windows Environment variable . The example includes the common Environment Variables, although use     “Dir env:\” to view the full list of variables


 Related Posts

Powershell Scripts for DBA

Powershell - run script on all sql servers

SQL Server Database Size and Free Disk Space Daily Report

Author: Tom Collins (


Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment on SQL Server – Windows Environment Variables and Powershell | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer