by oising
16. December 2011 11:47
I’m seeing a few errant companies have their installers throw their modules into ${env:systemroot}\WindowsPowerShell\1.0\Modules but this is not the right place. The only things that should go there are core operating system modules from Microsoft. So, where should you install them?
How to: Install a module for all users
- Create the folder ${env:programfiles}\YourProduct\PowerShell\Modules\
- Place your module (or modules) under this folder
- Add the folder from step 1 to the system scoped environment variable PSModulePath; consider embedding %ProgramFiles% to keep the environment string as short as possible
- Profit.
How to: Install a module for the current user
- Test for, and create if necessary the folder which is the result of this call (or equivalent in managed code): join-path ([environment]::GetFolderPath("MyDocuments")) WindowsPowerShell\Modules
- Copy your module or (modules) to folder at above
- Profit.
It’s as easy as that.
by oising
14. February 2011 19:23
I don’t generally write a lot of big scripts, but when I do, I usually fire up the PowerShell 2.0 graphical IDE. However, every time I use it to develop a module I always get irritated by the lack of any session management. When I hack away on a module, I usually have a couple of files open. I rarely finish a module in one sitting either, so I’ll come back to it in a day or two. I don’t always leave ISE open though so when I fire it up again I have to navigate to the location (or locations) where my files are and re-open them. Another annoying situation is playing with assemblies either by loading some external ones, or by using Add-Type to create your own in-memory types/classes. Debugging these things can get annoying as once loaded or created, you have to quit ISE to “clean” memory of all your dabblings. Well, I lie when I say you have to quit ISE. Strictly speaking, you can create a new tab with CTRL+T, close the old one and load all of your scripts into the new tab. Tabs are isolated from one another and assemblies loaded in one are not available elsewhere. So, taking advantage of this trick, let me introduce:
ISE Session Tools Module v1.0
I have more features planned for v1.1 to give ISE a proper “project” based feel to it, but in the interest of shipping something, v1.0 has the following features:
- AutoSaving of current session (files open in current tab.)
- This can be disabled and manually controlled if desired.
- Prompt to reload last session on ISE open
- A hint is shown to you reminding you of some of the files you had open.
- Press <enter> to accept the default of “Yes, reload my last session.”
- Restarting of the current tab
- Essentially cleaning memory and keeping your files open in the editor.
- You get prompted for this action. Press <enter> to accept default of “Yes, restart this tab.”
- All commands available under “Add-ons” menu for the mouse-fixated.

The commands exported by the module are:
- Restart-PowerShellTab (CTRL+ALT+R)
- Export-PowerShellTab (CTRL+ALT+S)
- Import-PowerShellTab (CTRL+ALT+L)
- Enable-AutoSaveSession (CTRL+ALT+A)
- Disable-AutoSaveSession (CTRL+ALT+X)
As you can see, they have hotkeys. This is possible because these commands are also bound to the “Add-ons” menu. I was careful to choose keys that do not interfere with IsePack if you like to use that module too.

Installing IseSessionTools
Extract the files into a folder named “IseSessionTools” under <my documents>\WindowsPowerShell\Modules\. In my ISE $profile, I have the following lines at the end of the file:
Import-Module ISESessionTools
Enable-AutoSaveSession
If you want to clear your session, disable autosaving and delete the session file at ~\psise.session.clixml.
Download ISE Session Tools Module v1.0
Have fun!
by oising
21. May 2010 21:58
If you want to do this, you won’t really need much of an explanation as to why I’m posting this. As to the rest of you, never mind; stick with your BigEndian Unicode (hint: powershell console and other console applications prefer ASCII) :)
First up, create yourself a Windows ISE Profile script that will be loaded by default when ISE starts (and/or when you open a new “Tab”)
# run this one-liner from within ISE through the interactive window (command pane):
if (-not (test-path $profile)) { md -force (split-path $profile); "" > $profile; psedit $profile }
Now, put this one-liner (well, it could fit on one line) in your $profile:
# watch for changes to the Files collection of the current Tab
register-objectevent $psise.CurrentPowerShellTab.Files collectionchanged -action {
# iterate ISEFile objects
$event.sender | % {
# set private field which holds default encoding to ASCII
$_.gettype().getfield("encoding","nonpublic,instance").setvalue($_, [text.encoding]::ascii)
}
}
Every time the tabs "files" collection changes, it will set the default save encoding to ASCII for all files in that tab. As the profile is loaded in each tab, all files in all tabs will default to ASCII when saving. No more "save as" annoyances; just hit save and ASCII will be used for encoding. "Save as" will still let you save as unicode if you wish.
Have fun!