Windows PowerShell Primer Tutorial

Windows PowerShell Primer Tutorial

Windows PowerShell Primer Tutorial

If you do desktop programming in Windows there is a good chance you do it under the supervision of the .Net Framework … framework … chortle, chortle.

Given that .Net Framework supervision, in Windows, you can write very sophisticated desktop programs involving Windows GUI concepts such as dialog boxes and buttons etcetera, etcetera, etcetera (it’s been too long), with C# or VB.Net, and great .Net Framework web applications using ASP.Net, via the Visual Studio IDE.

All of these programming options above produce code that you compile, normally using the Visual Studio IDE to simplify the “nuts and bolts” of how you do this.

You can create .Net Framework GUI programs with scripting as well, and the method for doing this is called PowerShell.

Today we perform a “Hello World” program using Powershell in today’s tutorial, and to do this, we leant heavily on this tutorial webpage which also talks about how to integrate a Powershell script with WPF (Windows Presentation Foundation).

Today’s tutorial “presentation” is a video one, presented by webcamming the screen of the Windows desktop screen with this MacBook Pro’s Photo Booth application’s webcam … as much as anything because don’t want to malign Photo Booth … see Air Server on Mac Primer Tutorial regarding my doubts … because, for lots of things, it still is the best idea, close to hand (for a primarily Mac desktop user). The resolution could be better but we’ll flesh out more below with some code and commentary … like a transcript … should you decide video is too difficult to decipher (or is too big to download, because, it is big) …

  • HelloWorld.ps1 … contents of in clipboard (via Notepad’s Edit->Select All Edit->Copy) as we enter the tutorial …

    $window = New-Object Windows.Window
    $window.Title = $window.Content = "Hello World of Powershell and WPF together."
    $window.SizeToContent = "WidthAndHeight"
    $null = $window.ShowDialog()
  • Windows icon (at bottom left)->All Programs>Accessories>Windows PowerShell>Windows PowerShell … wait to see Powershell prompt
  • Windows icon (at bottom left)->All Programs>Accessories>Windows PowerShell>Windows PowerShell ISE … see a scripting editor and supervisor
  • Into the top part Edit->Paste
  • Click green triangular Run button … does the right thing … a dialog box via scripting … similar to the dialog box in this tutorial’s picture … who’d have believed it?!
  • File->Save as… HelloWorld.ps1
  • Windows icon->Run … enter “powershell -sta”
  • At prompt, type in … Add-Type -assemblyName PresentationFramework
    Add-Type -assemblyName PresentationCore
    Add-Type -assemblyName WindowsBase
    .HelloWorld.ps1
  • …results in session dialog (with an error) as per … Windows PowerShell
    Copyright (C) 2009 Microsoft Corporation. All rights reserved.
    PS C:\Documents and SettingsOwner> Add-Type -assemblyName PresentationFramework
    PS C:\Documents and SettingsOwner> Add-Type -assemblyName PresentationCore
    PS C:\Documents and SettingsOwner> Add-Type -assemblyName WindowsBase
    PS C:\Documents and SettingsOwner> .HelloWorld.ps1
    The term '.HelloWorld.ps1' is not recognized as the name of a cmdlet, function
    , script file, or operable program. Check the spelling of the name, or if a pat
    h was included, verify that the path is correct and try again.
    At line:1 char:17
    + .HelloWorld.ps1 <<<<
    + CategoryInfo : ObjectNotFound: (.HelloWorld.ps1:String) [], Co
    mmandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
    PS C:\Documents and SettingsOwner>
  • In getting information about the error, type in …
    get-help about_signing
  • In solving the permission issue we’ve plumped (after a false lead trying to alter the “Block” on the Properties of the HelloWorld.ps1 file) for …
    get-executionpolicy
    set-executionpolicy remotesigned
  • Windows icon (right click)->Open Windows Explorer … find where HelloWorld.ps1 is … right click … choose Open with… Powershell … now this works (as evidenced by the dialog box in this tutorial’s picture today, as would the “powershell -sta” idea work now)

Actually, thinking on it, when we say … “who’d have believed it?!” … perhaps anybody programming in VBA and many Internet Explorer web programmers with VBScript and others (like perhaps the Basic programming language users), but nevertheless, find a scripting solution bringing up dialog boxes and other GUI objects very impressive.

If you are looking for the end result of today’s work see this picture else wait for the (huge) download of this video.

If this was interesting you may be interested in this too.

This entry was posted in eLearning, GUI, Software, Tutorials, Visual Studio and tagged , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

13 Responses to Windows PowerShell Primer Tutorial

  1. Hi my family member! I wish to say that this article is awesome, great written and include approximately all significant infos. I would like to see extra posts like this .

  2. Earl Hindman says:

    Hello.This article was extremely motivating, particularly because I was investigating for thoughts on this issue last couple of days.

  3. weblog says:

    Very good written story. It will be valuable to everyone who utilizes it, as well as me. Keep up the good work – i will definitely read more posts.

  4. software says:

    You actually make it seem so easy with your presentation but I find this topic to be actually something that I think I would never understand. It seems too complicated and very broad for me. I am looking forward for your next post, I’ll try to get the hang of it!

  5. *you have a great blog here! would you like to make some invite posts on my blog?

  6. Remarkably! It truly is as in case you read my mind! A person appear to know therefore considerably relating to this, just like you authored the book inside it or something. I feel that you can do with some images to drive the content material residence a bit, on top of that, this actually is great weblog. The outstanding study. I will definitely review again.

  7. I have read some good stuff here. Definitely price bookmarking for revisiting. I surprise how much attempt you put to make this sort of magnificent informative website.

  8. Remodelling says:

    Excellent site. Lots of useful information here. I am sending it to several pals ans also sharing in delicious. And obviously, thanks in your effort!

  9. Tech Blogs says:

    you are truly a good webmaster. The web site loading speed is amazing. It kind of feels that you are doing any unique trick. Furthermore, The contents are masterwork. you’ve performed a wonderful process in this matter!

  10. canada house says:

    you’re in reality a just right webmaster. The web site loading pace is incredible. It kind of feels that you are doing any distinctive trick. Moreover, The contents are masterpiece. you have done a magnificent process on this subject!

  11. Super-Duper web site! I’m loving it!! Will be back later to read some a lot more. I’m bookmarking your feeds also

  12. I like what you guys are up also. Such clever work and reporting! Carry on the fantastic performs guys I have incorporated you guys to my blogroll. I consider it’s going to enhance the worth of my site .

  13. great put up, very informative. I wonder why the opposite specialists of this sector do not notice this. You must proceed your writing. I’m confident, you’ve a huge readers’ base already!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>