I’ve seen many interesting things done with PowerShell ISE, so I decided to play with it myself. One thing I don’t like about any powershell host: if you Import-Module or Add-PsSnapin to session in $profile it usually takes some time before you can do anything. And from time to time you do not really need those modules/ snapins. So what could one do? Well, because of ISE functionality you can have few cosole-tabs (as far as I can tell up to 8). So my idea was to create 2 powershell tabs on start: one ‘empty’, and next one – with everything loaded, and switch to first one while second is loading ‘stuff’. After that I decided that it would be cool to have an option to switch between tabs. At first I’ve just created functions, f#, that would move me to tab no #. But that was not enough for me – so I played a bit with ISE menus and got Alt + # shortcuts for each new tab, together with menu option to switch to different tabs. Whole $profile can be seen below:
-
$tabs = $psISE.PowerShellTabs
-
$curtab = $tabs[$tabs.Count–1]
-
$ISEOpt = $psISE.Options
-
$ISEOpt.OutputPaneBackgroundColor = ‘black’
-
$ISEOpt.OutputPaneTextBackgroundColor = ‘black’
-
$ISEOpt.OutputPaneForegroundColor = ‘white’
-
$TabsMenu = $curtab.AddOnsMenu.Submenus.Add(‘Tabs’,$null,$null)
-
if ($curtab -eq $tabs[0]) {
-
$curtab.DisplayName = ‘NoProfile’
-
$newTab = $tabs.Add()
-
} else {
-
$curtab.DisplayName = “PoSh # $($tabs.IndexOf($curtab))”
-
$NewTabIndex = $tabs.Count
-
Invoke-Expression “`$SwitchToMe = { `$tabs.SetSelectedPowerShellTab(`$tabs[$NewTabIndex-1]) }”
-
for ($i = 0; $i -lt $tabs.Count – 1; $i++) {
-
if ($NewTabIndex -le 9) {
-
Invoke-Expression “`$SwitchTo = { `$tabs.SetSelectedPowerShellTab(`$tabs[$i]) }”
-
[void] $Mymenu.Submenus.Add($curtab.DisplayName, $SwitchToMe ,“ALT + $NewTabIndex”)
-
} else {
-
# That should not happen cause limit is 8
-
Write-Host -ForegroundColor Red “Can not add this tab to menu – move to it using CTRL + TAB”
-
}
-
[void] $TabsMenu.Submenus.Add($tabs[$i].DisplayName, $Switchto, “ALT + $($i+1)”)
-
}
-
$tabs.SetSelectedPowerShellTab($tabs[0])
-
Add-PsSnapin Quest*
-
Import–Module @(‘WPK’,‘IsePack’)
-
. “C:\Program Files\Quest Software\Management Shell for ADqsft.ps1”
-
}
It also changes default colours in OutPutPane to black background – white foreground.
The main problem I had was with “action” part of Submenus.Add method – it takes scriptblock, but I was not able to force it to expand variables, and got unpredictable results. Once I used Invoke-Expression to get proper [scriptblock] variable it all went fine. Two things I would like to fix:
* when I press alt + # I get method displayed – would love to make it ‘silent’
* if I close some tab and add next it all get messed up (two tabs with same name if it was in a middle, errors when adding new tab…)
But it does most of things I needed, and now I get my prompt very quick and if I need WPK, IsePack or Quest cmdlets – all I need to do is switch to second tab. 🙂 ISE rocks. 😀