PowerShell In GUI Blog

PowerShell GUI Box Just In A Few Clicks

Archive for the ‘PowerGUI add-on’ Category

An Infinitesimal Update To ObjectBrowser

leave a comment »

Hi, today’s update is really small.

– added a progress bar during the collecting Current AppDomain and GAC. This should do the GAC loading slightly less painful.

– the ability to be run from command line powershell as well as from ISE is now restored. Please use the following instruction to import the module:

Import-Module Add-on.PSDevStudioLite.ObjectBrowser -Force

Other changes relate to internal code structure and not to be seen right now in the GUI. As usual, the download location is here: http://www.box.net/shared/ot56ct7ngl


Which Icons Are Shipped With Object Browser?

leave a comment »

Actually, what is the easiest way to display icons? Create a control like ListView? Maybe. Let’s create a handful of windows, just to observe how short the code might be.

First, import both modules, SuiteCore and ObjectBrowser (here and thereafter the PSDevStudioLite modules set is in use).

After that you are able to use the function set shipped with the package. The following simple code creates windows, which in turn demostrate icons.

function createWindows
    for($private:i = 0; $private:i -lt $imagesList.Count; $private:i++)
        $tw2 = New-SEToolWindow -Control (([System.Windows.Forms.ListBox]$lb = New-Object System.Windows.Forms.ListBox) | %{$lb;}) `
            -TitleBarText ("aaa" + $private:i) `
            -WindowName ("aaaaa" + $private:i) `
            -Image $imagesList[$imagesList.Keys[$private:i]] `
            -Visible $false -State TabbedDocument;
        Write-Host $private:i $imagesList.Keys[$private:i]
        $se.ToolWindows[("aaaaa" + $private:i)].Visible = $true;


In the GUI you might easily see all of them by clicking a triangle, allowing you to make a list of all open documents:

To clean up the document list is also simply, even somewhat simpler that to fill up:

function removeWindows
for($private:i = 0; $private:i -lt $imagesList.Count; $private:i++)
Remove-SEToolWindow -WindowName ("aaaaa" + $private:i);



Requirements: PSDevStudioLite.SuiteCore Beta and higher, PSDevStudioLite.ObjetBrowser Beta ang higher.


Note: all above are never be supported by quest, wasn’t and won’t be.


leave a comment »

Object Browser is uploaded to the link http://www.box.net/shared/ot56ct7ngl

This version comprises of two small improvements. The first one is a moving to be used in Strict mode. The second, and resulting the first one, is an improvement in showing private members.

Written by Alexander Petrovskiy

March 21, 2011 at 7:41 pm


leave a comment »

As I languidly tested what was released recently as ObjectBrowser July, 12th 2010, I remembered a couple of bugx I always wanted to fix. Today’s shipped with

– search by name

– PleaseWait window

both fixed. As usual, the direct link is the same: ObjectBrowser

Written by Alexander Petrovskiy

March 18, 2011 at 7:49 pm

How to deal with -RoutedEvent parameter in WPK

with 3 comments

After ScriptEditor add-ons having been brought to the World, we were asked by our community enthusiasts about how to handle events.

The problem is that self-contained environments (also known as containers, please refer to about_scopes text file) are not described well. There are in Powershell three more or less contradictory things as follows:

– scopes

– containers that don’t or almost don’t obey the rules of scoping

– three types of variables: user-created, automatic and preference

I’m planning to give an article later this week, but at the moment I’m putting out the immediate example meant to improve the situation.

The story began from a question asked by some guy who created a universal add-on, targeted to work in both powershell_ise and PowerGUI environments. The exact complaint was that ‘my window starts from a command, but in the ise IDE events fired, whereas in the PowerGUI IDE events don’t fire’.

Not planning to spent time right now discussing why MSFT’s containers work better them Quest’s ones, I’d like to grab your attention to the following code sample which is a module, but can also be used as a script:

#Only to be run in the ScriptEditor
if ($host.Name –eq 'PowerGUIScriptEditorHost') {
#region function
function script:Show-TestWindow {
    param($UseGlobal = $false)
    #region event handler
    $global:evt = 
    {    #Declaration of event variables
        #Variant #1
        if ($Event -ne $null) {Write-Host '001' $Event;}
        if ($EventSubscriber -ne $null) {Write-Host '002' $EventSubscriber;}
        if ($Sender -ne $null) {Write-Host '003' $Sender;}
        if ($SourceArgs -ne $null) {Write-Host '004' $SourceArgs;}
        if ($SourceEventArgs -ne $null) {Write-Host '005' $SourceEventArgs;}
        if ($This -ne $null) {write-host '006' $This;}
        if ($global:Event -ne $null) {Write-Host '011 global' $global:Event;}
        if ($global:EventSubscriber -ne $null) 
        {Write-Host '012 global' $global:EventSubscriber;}
        if ($global:Sender -ne $null) 
        {Write-Host '013 global' $global:Sender;}
        if ($global:SourceArgs -ne $null) 
        {Write-Host '014 global' $global:SourceArgs;}
        if ($global:SourceEventArgs -ne $null) 
        {Write-Host '015 global' $global:SourceEventArgs;}
        if ($global:This -ne $null) 
        {Write-Host '016 global' $global:This;}            
        #An additional demonstrable result
        [System.Windows.Forms.MessageBox]::Show("Event fired!");
    #endregion event handler                                        
    #region RoutedEvent hashtable
    [System.Collections.Hashtable]$global:ht = `
        New-Object System.Collections.Hashtable;
    $global:ht.Add("Click", $global:evt);
    #endregion RoutedEvent hashtable    

    #region window
    New-Window -WindowStartupLocation CenterScreen `
        -Width 100 -Height 100 `
        -Show -On_Loaded {
        $global:btnClickMe = $window | Get-ChildControl btnClickMe
        } {
            #region layout
            New-Grid {
                #region button
                New-Button -Name btnClickMe -Margin "20,20,0,0" `
                    -Height 23 -Width 50 `
                    -HorizontalAlignment "Left" `
                    -VerticalAlignment "Top" `
                    -Content "Click Me" `
                    -On_Click $global:evt -RoutedEvent $global:ht
                #endregion button            
            #endregion layout
    #endregion window
#endregion function

    $se = [Quest.PowerGUI.SDK.ScriptEditorFactory]::CurrentInstance
    $cmd1 = New-Object Quest.PowerGUI.SDK.ItemCommand("Hidden", "EventTestLocal")
    #Using a scriptblock
    $cmd1.ScriptBlock = {script:Show-TestWindow $false;};
    #Or using Invoking or Invoked
    #[System.EventHandler]$global:wh = {script:Show-TestWindow; };
    $keys = [System.Windows.Forms.Keys]::Control -bor `

Write-Host "Module WPK.Event.Test loaded";

#We can use this as a script

After turning on the module, you obtain our window by pressing Ctrl+5. Event fires at the moment you click a button providing both command line and messageboxed results.

Please notice the scoping of results printed out into the Console. $This is always global. First, all automatic variables are global. Second, there is a comment in the ‘Writing User Interfaces with WPK’ document shipped with the PowerShellPack. The doc mentioned says that $this, taken in events, ‘is where the event is coming from’.

Why $this is global instead of being script-scoped? Because containers behave slightly differently.

Additional note that I should mention is that you might declare parameters of an event as local (i.e. param($Sender)) or as global ones (that is param($global:Sender)) depending on life cycle of objects you planned.

Written by Alexander Petrovskiy

June 21, 2010 at 9:20 am