PowerShell In GUI Blog

PowerShell GUI Box Just In A Few Clicks

Archive for the ‘PowerGUI’ Category

Reign over your network with only a Kindle?

with 2 comments

Although any kind of advertisement is not the intent I am writing on these pages, the latest buzz motivated me too to drop a word on web powershell.

Have you ever thought about how to manage your network(s) laying languidly upon the beach, tanning and using the worldwide free Internet access? I have. Now I’ll be showing the facts and you the reader is the judge if it is possible to administer maximally remotely from a resort or not yet.

The check list of preparations is of three items (with exception of course sandals, towels and so forth):

  • a Kindle connected to a some network (Wi-Fi or GSM 3G is what is needed) from $114
  • a Mobile Shell box – from one 3G KIndle or two Wi-Fi special offer’s Kindles apiece
  • some scripts, especially changing security settings or touching the file system your boss’s host, to make the life breathtakingly sharper.

At first, buy and register a Kindle and download your copy of MobileShell here. While the latter can be downloaded on a monthly trial basis, the former needs defraying (you may try to use Amazon Return policy, though. If your test failed only). Go throught the text below if you have already checked all items above.

Install the software as said here (won’t you read the manual going to a beach?) and out, out to the beach. Any tests on a Kindle can be performed from there, for what else reason you sponsored the development of Pearl screens buying it?

Let’s connect to the MobileShell host. The only note here is that you need use strictly the mobile version by typing https://host_name_or_address/MobileShell/mobile , otherwise the Kindle bravely tries to swallow the desktop version, its browser got swollen and died until the device restarts.

ImageAfter Kindle said you your rights, you are connected and may or may not see the choice if somebody knowing your login and password, you for example, was last night here:

ImageWe are leaving out the Favorites list

Imagesince we wanted to run a script or a piece of code. Probably unlike you, I forgot to write scripts and will run something useless. Meet the Kindle PowerShell Code Editor:

ImageOf two colors, black and white, isn’t it? The very conservative design, easier than ‘vi’, though.

ImageSome English IntelliSense helped us and our script is ready!

ImageThe first run is in a second, take a sip of what you drink on the sand and press the Run button!

ImageOops, the folder where I stored screenshots is where I’m sitting and I’m sitting not on the MobileShell host. But it would have found the folder if I’d written right, beyond the doubts.

Written by Alexander Petrovskiy

May 19, 2011 at 8:49 pm

WordPress PowerShell Code Coloring Test

with one comment

I have already written about how it’s possibly to post Powershell code here. As a year turned, why don’t check the state of affairs again?

My example is very simple and doesn’t cover all aspects of code. On the other hand, great sheets of code are not what is easily comparable with eyes.

1. This way my example is eyed in ISE:

Image

Bugs are rare, however, it’s necessary to list them:

1.1 String data used without quotes is colored as a function (line 10)

1.2 Methods are not colored. It’s a typical trick, however, since nobody may know what it will be after the run of code. After having run the code, it’s considered here that no reason to re-color already colored code. (lines 10 and 42)

1.3 Property ‘Value’ is not colored (line 42).

Anyway, the coloring left the reader in a mood that all is healthy here.

2. Using Copy as HTML in PowerGUI 2.4 and Chrome 11, after adding manually line breaks (why doesn’t it type
s?), spaces and deleting trailing spaces after backticks (not in this sample), the following is workable:

cls
#region WordPress posting code test 
#this is a test of Powershell code coloring
[string]$stringVar1="string 1"
[string]$private:stringVar2='string 2'
[string]$script:stringVar3=
@' 
string data 
'@ 
[scriptblock]$global:sb= {{Write-Hostscriptblock}.Invoke();}; 
function 
write1{Write-Host $stringVar1;} 
function private:write2 
{param([string]$str2='')Write-Host $str2;} 
function script:write3 
#this is a function

Write-Host$script:stringVar3

function global:Print-SB 

<# 
.SYNOPSIS 
This is a code coloring test. 
.DESCRIPTION 
This test function represents an advanced Powershell function syntax. 
.PARAMETER 
Param Demonstrates how a scriptblock can be passed as a reference. 
.EXAMPLE 
PS C:\> Print-SB ([ref]$sb) 
#> 
[CmdletBinding()] 
param( [Parameter(Position=0, Mandatory=$true)] 
[ref]$Param 

Begin{} 
Process{$Param.Value.Invoke()} 
End{} 

write1 
private:write2 $private:stringVar2
script:write3 
Print-SB ([ref]$global:sb
#endregion WordPress posting code test

2.1 In the second code snippet we have numerous problems with names of functions, both where they are declared and where they are called.

2.2 Write-Host inside the second function

2.3 Such stuff like attributes in an advanced function.

To conclude this section, use the Copy as HTML option is a choice if manual editing doesn’t fatigue you.

3. WordPress provides a set of tags. Several parameters might do the life of a codeblogger simpler, especially 'highlight'.
cls
#region WordPress posting code test
#this is a test of Powershell code coloring
[string]$stringVar1 = "string 1";
[string]$private:stringVar2 = 'string 2';
[string]$script:stringVar3 =
@'
string data
'@
[scriptblock]$global:sb = {{Write-Host scriptblock}.Invoke();};
function
write1{Write-Host $stringVar1;}
function private:write2
{param([string]$str2 = '')Write-Host $str2;}
function script:write3
#this is a function
{

	Write-Host $script:stringVar3;
}
function global:Print-SB
{
<#
	.SYNOPSIS
		This is a code coloring test.

	.DESCRIPTION
		This test function represents an advanced Powershell function syntax.

	.PARAMETER  Param
		Demonstrates how a scriptblock can be passed as a reference.

	.EXAMPLE
		PS C:\> Print-SB ([ref]$sb)
#>
	[CmdletBinding()]
	param(
		  [Parameter(Position=0, Mandatory=$true)]
		  [ref]$Param
		  )
	Begin{}
	Process{$Param.Value.Invoke()}
	End{}
}
write1
private:write2 $private:stringVar2;
script:write3
Print-SB ([ref]$global:sb)
#endregion WordPress posting code test

However, the overall state is not appropriate, from my point of view. Yes, I know that the 'Frustration-Free' trademark is not WordPress's (as it is not Quest's too), but there is a room for improvement:

3.1 Variable names (lines 5, 6, 46, 48)
3.2 Function declarations and names (lines 11-13, 15, 21, 45-48)
3.3 A blob string (lines 7-9)
3.4 A specific to advanced functions comment-description (lines 23-35)
3.5 Types (lines 4-6, 10, 14)
3.6 Unquoted string (line 10)
I'll report these problems to Happiness engineers, maybe they share a bit of their happiness? 😉

Written by Alexander Petrovskiy

April 27, 2011 at 6:37 am

Posted in ISE, PowerGUI, Powershell, WordPress

Tagged with

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.

cls
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;
    }
}

createWindows;

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

Image

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);
}
}

removeWindows;

 

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

http://www.box.net/shared/ot56ct7ngl

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

OB 1.0.0.3

leave a comment »

Object Browser 1.0.0.3 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

OB 1.0.0.2

leave a comment »

As I languidly tested what was released recently as ObjectBrowser 1.0.0.1 July, 12th 2010, I remembered a couple of bugx I always wanted to fix. Today’s 1.0.0.2 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 put your Powershell code onto WordPress page

with 2 comments

Supposing, you use the PowerGUI ScriptEditor. After writing a valuable fragment of code, you wanted to publish it in your WordPress blog. What would you do?

  • copy and Paste as Plain Text into your post?
  • copy and Paste from Word into your post?

Nope, the easiest way to do that is to

  • Save your code As an HTML page
  • open the page in any text or HTML editor of your choice
  • copy all from <pre> tag to </pre> inclusively (don’t bother about Tools -> Options -> Text Editor -> Tab; both states work)
  • activate ‘HTML’ tab in ‘Add New Post’ if you have ‘Visual’ one activated
  • paste to Edit Post frame.

Now this code in your blog is ready to be copied and pasted in Editors of your followers; it works immediately without any editing.

How to publish your code from Powershell ISE? Copy and paste it into a new document of PowerGUI ScriptEditor and just follow recipe above…

Written by Alexander Petrovskiy

July 5, 2010 at 6:49 pm

Posted in PowerGUI, Powershell, WordPress

Tagged with

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:

cls
#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
        param(
            $Event, 
            $EventSubscriber, 
            $Sender, 
            $SourceArgs, 
            $SourceEventArgs)
        #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; };
    #$cmd1.add_Invoked($global:wh);
    $keys = [System.Windows.Forms.Keys]::Control -bor `
        [System.Windows.Forms.Keys]::D5
    $cmd1.AddShortcut($keys)
    try{$se.Commands.Remove($cmd1);}catch{}
    $se.Commands.Add($cmd1)

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

#We can use this as a script
#Show-TestWindow
}

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

A Very Simple Object Browser

with 4 comments

As I again decided to continue writing for the PowerGUI platform, which I’m personally user of, here is one another teaser. This object browser was written while the ScriptEditor object model had been developing and nothing promised that the thing would be living long. However, I used the thing several times after stopping of development, so that I understood it may be needed for somebody else.

Image

I revised what has been done by now and the facts are:

– collecting data from the CurrentDomain, the GAC and from several manually loaded libraries

– displaying public members as well as private.

There are some bugs including broken search across asssemblies.

Features to do list includes

– creating snippets of code for selected definitions

– bookmarks

– rearranging controls and menu

– all other data sources 🙂

Written by Alexander Petrovskiy

June 14, 2010 at 1:34 pm

How difficult to paint a graphical GUI plug-in?

with 2 comments

Got bored with the PowerGUI grid? Nothing new may be added to the such well-known product? How do I understand such a mood!

Being responsible for testing of several Quest’s products, I had not at once thinking to base on the PowerGUI something bright, interesting, new… But poor object model stopped me. Does anybody want to dig into asynchronous operations while writing a script? Even your script is working in the same process as the host application, you definitely can achieve anything in a .NET app, but it’s so unconfortable to touch something in the another thread without proper debugger (as in the AdminConsole).

Below is a typical teaser. By now, the PowerGUI 2.1 has been released, but, supposingly not to be publicly viewed until the TechEd, it hasn’t been published yet.

The new anmazing feature I want to reveal is the some SDK helping you to pluginize the application. Provided as an unfriendly object model, it had been wrapped by enthusiasts, one of them is the your author, me. having shared the ideas and our code with another enthusiast, I realized, that not all ideas of how the product cab be extended were spread across the enthusiasts. Surprisingly, not too many people began writing GUI plug-ins.

So, I’m going to demostrate a screen almost completely occupied with my plug-in. It’ll be called add-in, however I’d prefer something unique like poshlet or something like. The poshlet I mentioned consists of Designer pane, ToolBox with a set of Windows.Forms controls and the property window. All of them use the great Actipro basis. There is the fourth component, that’s totally invisible excepting a menu item. I’ll tell you about the fourth below. Now we can see the plug-in at the moment of custom GUI painting.

Image

Okay, might you say, it’s not new, there are a lot of designers in the numerous IDEs and how can it help me with my scripts? The anwer is that there is a code generator allowing you to run what you painted as soon as it would be, for example, SharpDevelop.

Image

Differently from, for instance, SAPIEN’s free IDE, this poshlet is aimed to create dockable applications in the PowerGUI hosts family.

This is the result of code generation that will be definitely proofread later.

At the end, by pressing F5, we have the window that had been painted a few seconds ago.

Image

At left is the window created dynamically whereas at right is what we painted.

Written by Alexander Petrovskiy

June 3, 2010 at 1:24 am

Design a site like this with WordPress.com
Get started