PS: Working with Environment Provider

PROVIDER NAME Environment DRIVES Env: SHORT DESCRIPTION Provides access to the Windows environment variables. DETAILED DESCRIPTION The Windows PowerShell Environment provider lets you get, add, change, clear, and delete Windows environment variables in Windows PowerShell. The Environment provider is a flat namespace that contains only objects that represent the environment variables. The variables have no child items. Each environment variable is an instance of the System.Collections.DictionaryEntry class. The name of the variable is the dictionary key. The value of the environment variable is the dictionary value. The Environment provider exposes its data store in the Env: drive. To work with […]

Read more

PS: Best Practices Referring Environment Variables in Powershell Programming

A very good practice to retrieve environment variables values is to refer them as scalar values via $env context   PS C:> echo $env:appdata C:UsersgovardhanAppDataRoaming PS C:> write-host $env:appdata C:UsersgovardhanAppDataRoaming PS C:> If you are in practice of using Get-Item to retrieve environment variables, be cautious on possible typo of using $Env which would fail as shown below, so don’t use $Env while retrieving environment variables via Get-Item.   PS C:> Get-Item Env:UserName Name                           Value —-                           —– USERNAME                       Govardhan PS C:> Get-Item $Env:UserName Get-Item : Cannot find path ‘C:Govardhan’ because it does not exist. At line:1 char:9 + Get-Item <<<<  […]

Read more

PS: Working with Environment Variables in PowerShell

Command to list all Environment Variables: PS C:> Get-ChildItem Env: (You can also use get-item) Name                           Value —-                           —– ALLUSERSPROFILE                C:ProgramData APPDATA                        C:UsersgovardhanAppDataRoaming CommonProgramFiles             C:Program FilesCommon Files COMPUTERNAME                   TEST-PC1 ComSpec                        C:Windowssystem32cmd.exe FP_NO_HOST_CHECK               NO HOMEDRIVE                      C: HOMEPATH                       Usersgovardhan LOCALAPPDATA                   C:UsersgovardhanAppDataLocal LOGONSERVER                    \TESTDOM-DC01 NUMBER_OF_PROCESSORS           2 OS                             Windows_NT Path                           %SystemRoot%system32WindowsPowerShellv1.0… PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;…. PGInstallDir                   C:Program FilesPowerGUI PGSnippetPath                  C:Windowssystem32WindowsPowerShellv1.0Mo… PROCESSOR_ARCHITECTURE         x86 PROCESSOR_IDENTIFIER           x86 Family 6 Model 15 Stepping 13, GenuineIntel PROCESSOR_LEVEL                6 PROCESSOR_REVISION             0f0d ProgramData                    C:ProgramData ProgramFiles                   C:Program Files PSModulePath                   C:UsersgovardhanDocumentsWindowsPowerShel… PUBLIC                         C:UsersPublic QTJAVA                         C:Program FilesJavajre6libextQTJava.zip SESSIONNAME                    Console SIKULI_HOME                    C:Sikuli SystemDrive                    C: SystemRoot                     C:Windows TEMP                           C:UsersGOVARD~1AppDataLocalTemp TMP                            C:UsersGOVARD~1AppDataLocalTemp USERDNSDOMAIN                  TESTDOM.COM USERDOMAIN                     TESTDOM USERNAME                       Govardhan USERPROFILE                    […]

Read more