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

PS: Directory Listing

Command to list all Files greater than a specified file size: PS D:> Dir $env:windir | Where-Object { $_.Length -gt 10MB }     Directory: C:Windows Mode                LastWriteTime     Length Name —-                ————-     —— —- -a—         3/18/2011  11:00 PM  262189444 MEMORY.DMP PS D:>   Format the File listing by the File sizes in KB, MB, GB’s:   PS D:> Dir $env:windir | Where-Object { $_.Length -gt 1MB } | Format-Table Name, { [int]($_.Length/1MB) } -Auto Name                   [int]($_.Length/1MB) —-                  ———————- explorer.exe                               2 MEMORY.DMP                               250 ntbtlog.txt                                1 setupact.log                               3 WindowsUpdate (1).log                      2 WindowsUpdate.log                          1 wweb32.dll                                 1 PS D:>   Display matching Files with sizes […]

Read more

PS: Querying Event Viewer made easy

List all error events since a specified date in the past: Set a variable to a date that you want to see all error events after that: PS C:> $today = get-date 2/15/11 PS C:> get-eventlog -logname application -Source "*error*" -after $today | ft -auto Index Time         EntryType   Source                  InstanceID Message —– —-         ———   ——                  ———- ——- 9783 Mar 13 10:42 Information Windows Error Reporting       1001 Fault bucket , type 0… 9594 Mar 07 00:08 Information Windows Error Reporting       1001 Fault bucket , type 0… 9272 Mar 06 19:34 Information Windows Error Reporting       1001 Fault bucket , type 0… 9271 […]

Read more