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
$env:COMPUTERNAME $env:NUMBER_OF_PROCESSORS $env:OS $env:PROCESSOR_ARCHITECTURE $env:PROCESSOR_IDENTIFIER $env:PROCESSOR_LEVEL $env:PROCESSOR_REVISION $env:SystemDrive $env:SystemRoot $env:USERDNSDOMAIN $env:USERDOMAIN $env:USERNAME $env:USERPROFILE $env:LOGONSERVER $env:HOMEDRIVE $env:SESSIONNAME $env:windir
Powershell - run script on all sql servers
SQL Server Database Size and Free Disk Space Daily Report
This is only a preview. Your comment has not yet been posted.
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.
Posted by: |