Take advantage of Launchy to speed up how you find and open files, programs or websites and move faster while reducing the likelihood of errors by using Powershell to automate repetitive manual tasks.

Configure Launchy

When you have installed Launchy, type "Alt + Space" and in the Launchy window that appears click on the wheel on the right hand side and then in the General tab, select the "Hide Launchy when it loses focus" checkbox.

PowerShell - Install and configuration

To install PowerShell, go to the main PowerShell site and use the Downloads menu that can be found over on the right.

To open a PowerShell window:

Alt+Space (Launchy) 
Type power + Return 

If PowerShell does not appear in the list of options, then click on the wheel on the right-hand side again but this time choose the Catalog tab. Under this tab you should be able to see at the left the included File Types (underneath are two checkboxes for including executables and directories) and on the right the Directories that Launchy uses to catalogue the contents of the computer. At the bottom of the tab there is a Rescan Catalog button and the number of elements that are currently contained within the index. After any change to the configuration of the Catalog always remember to use the Rescan Catalog button to update Launchy's catalogue.

Depending on the configuration of the computer's file system and where you installed PowerShell you may have to modify some of these settings. You may also want to add file extensions for other commonly used file types (*.pdf, *.doc, *.txt) or investigate the functionality provided by the Plugins tab.

In the PowerShell window type the following to allow the execution of our scripts:

Set-ExecutionPolicy RemoteSigned + Return

The variable $profile contains the preconfigured location of the PowerShell configuration filel (we're using the command write-host to see it's value):

write-host $profile + Return 
C:\Documents and Settings\hgilmour\Mis documentos\
WindowsPowerShell\Microsoft.PowerShell_profile.ps1

If the directory (WindowsPowerShell) doesn't exist, create it and then type:

notepad $profile

For an idea of what can be added into this file you can use this Microsoft.PowerShell_profile.ps1 gist as an example.

PowerShell and environmental variables

As you will have seen in the example profile gist there are a number of different ways to access environmental variables.

This option reads them as soon as they have been created (for the second argument we need to choose between variables stored at the User or the Machine (System) level):

[Environment]::GetEnvironmentVariable('WORKSPACE_HOME', 'User|Machine')

The use of this method without the second argument reads the variables from the environment of the current PowerShell process and will read variables that have been created at the User or Machine level provided that they existed when this PowerShell process was started.

The second option, on the other hand, will only read those variables which were in existence when the current PowerShell window was created.

$env:WORKSPACE_HOME

The former method is the most useful because it gives us more flexibility and it lets us obtain changes that have been made to environmental variables without having to reload the environment (which in practice means closing the current PowerShell window and opening another).

Launchy and environmental variables

Be careful if you launch your PowerShell processes from Launchy if what you need to do is reload the environment. Launchy is also a Windows process and as such it loads it's own "snapshot" of the environment, which does not change during the lifetime of the Launchy process and which it propagates to all of the processes that it launches. This means that when you kill a PowerShell process, with the intention of reloading the environment when you start-up a new one, if you start this new process from Launchy without restarting it too, then the environmental variables will not reflect any changes.

For this reason we prefer the following option for accessing variables in our PowerShell scripts since it's ability to access new or changed variables (those changes that do not appear in $env) isolates us from this type of problem:

[Environment]::GetEnvironmentVariable('WORKSPACE_HOME', 'User|Machine')

Useful links

PowerShell and Environmental Variables

Powershell Blog

TechNet Script Centre Repository

Microsoft Scripting Guys

Books

I've not had the opportunity to read this book but it seems to have received very good reviews.

PowerShell in Action

Filed under: tools

comments

There are no comments.