Tuning your ISE

After being silent for a while it’s time to explode with some really great stuff!
Let’s start with the environment you develop the scripts in. There are several options out of there: free PowerGUI – very popular IDE but doesn’t look nice for me, Sapiens PowerShell Studio – seems to be a powerful tool but costs 389$ at the moment. So I look back to the ISE that is bundled with WMF 4.0. Some vital features missing, so we need to put in an effort to fill the blanks. But it’s not as hard as you might think. That’s the way to go!

$Env:Path
The first step is to customize your profile, which is loaded every time you start the ISE. The $profile variable will suggest you the file location. Begin with filling the file by adding the necessary paths to $Env:Path variable, eg:
$env:Path += ';C:\Program Files (x86)\EMC\Navisphere CLI;'
There is another way to modify environment variables. For instance, this is how to add the path where ISE will search for modules:
[System.Environment]::SetEnvironmentVariable('PSModulePath',$env:PSModulePath + ";$ModuleDir",'Machine')
Then you can Import all necessary modules and snap-ins, though in the recent PoSh versions they are auto-loaded.

Snippets
You can hide the default snippets
$psISE.Options.ShowDefaultSnippets = $false
and import your own ones. If you wrapped them into the module, run this:
Import-IseSnippet -Module PurpleScreen

Help
To keep the help docs up to date (say, max 4-weeks old), check the file, where the last help update date stored, and run Update-Help if necessary:

Passwords
The next step is to take care of storing passwords in an easy yet secure way, so you have an access to them once ISE started. Windows provides you with the all necessary tools. First, execute the line below and enter your password. That will store the encrypted password string in the $PassDir folder (needs to be done only once). Windows handles the private key, which is your ‘profile’, thus the password can be decrypted only after you are authenticated.

Then you can load the password in the current session and compile the Credential object:

Text processing
Next is to add some text-processing capabilities for some reason missing in the standard bundle and expose them with hotkey combinations (the functions’ source code will be revealed in the next blog posts introducing my module). You may change hotkeys at your discretion, but keep in mind that some of them are already occupied with built-in ISE commands.

Since we are VMware guys (aren’t we?), we need a hotkey for setting PowerCLI properties and connecting to multiple vCenter/vCloud servers (a couple of VIProperties as a bonus):

Certificate
Also you may need the certificate in hand to sign the scripts you write. If it’s been already imported in the cert store on your machine, just push it to the variable with:
$CodeSigningCert = gi Cert:\LocalMachine\my\<thumbprint>
To sign a script using the cert and publicly available timestamp server run
Set-AuthenticodeSignature -Certificate $CodeSigningCert -FilePath "$ScriptDir\PurpleScreen.psm1" -TimestampServer http://timestamp.globalsign.com/scripts/timestamp.dll

Remote sessions
Need to connect to an interactive remote session / load cmdlets from remote session with a hotkey? That’s pretty easy (more on remote sessions, configurations, CredSSP, etc. in the separate post):

You can see some handling of opened tabs here. The main thing I was missing was keeping the session state between ISE reloads. I’d like to pick up the things from where I left off by auto-loading all opened tabs and files from my previous session. This part was successfully implemented with Save-ISEState and Load-ISEState functions (stay in touch for PurpleScreen module).

It will also show all currently available command shortcuts for convenience.

GitHub
And in the end some really neat feature – GitHub integration! Press Ctrl+Alt+G to open GitHub tab with your project’s local repository (needs GitHub desktop app installed and repository configured)

That’s all for now!

Stay tuned and remember to follow the main rule – once written, share with a community!