{"id":12780,"date":"2016-01-13T05:05:45","date_gmt":"2016-01-12T19:05:45","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=12780"},"modified":"2016-01-16T20:42:36","modified_gmt":"2016-01-16T10:42:36","slug":"windows-powershell-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/windows-powershell-primer-tutorial\/","title":{"rendered":"Windows PowerShell Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Windows\/DotNetFramework\/Powershell.mov\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Windows PowerShell Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Windows\/DotNetFramework\/Powershell.jpg\" title=\"Windows PowerShell Primer Tutorial\"    \/><\/a><p class=\"wp-caption-text\">Windows PowerShell Primer Tutorial<\/p><\/div>\n<p>If you do desktop programming in Windows there is a good chance you do it under the supervision of the <a target=_blank title='Net Framework information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/.NET_Framework'>.Net Framework<\/a> &#8230; framework &#8230; <font size=1>chortle, chortle<\/font>.<\/p>\n<p>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&#8217;s been too long), with C# or VB.Net, and great .Net Framework web applications using ASP.Net, via the <a target=_blank title='Visual Studio downloads' href='http:\/\/www.visualstudio.com\/'>Visual Studio<\/a> <a target=_blank title='Integrated Development Environment information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Integrated_development_environment'>IDE<\/a>.<\/p>\n<p>All of these programming options above produce code that you compile, normally using the Visual Studio IDE to simplify the &#8220;nuts and bolts&#8221; of how you do this.<\/p>\n<p>You can create .Net Framework GUI programs with scripting as well, and the method for doing this is called <a target=_blank title='PowerShell information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Windows_PowerShell'>PowerShell<\/a>.<\/p>\n<p>Today we perform a &#8220;Hello World&#8221; program using Powershell in today&#8217;s tutorial, and to do this, we leant heavily on <a target=_blank href='http:\/\/blogs.msdn.com\/b\/powershell\/archive\/2008\/05\/22\/wpf-powershell-part-1-hello-world-welcome-to-the-week-of-wpf.aspx?PageIndex=2' title='Powershell and WPF Hello World tutorial ... thanks' >this tutorial webpage<\/a> which also talks about how to integrate a Powershell script with WPF (<a target=_blank title='WPF information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Windows_Presentation_Foundation'>Windows Presentation Foundation<\/a>).<\/p>\n<p>Today&#8217;s tutorial &#8220;presentation&#8221; is a video one, presented by webcamming the screen of the Windows desktop screen with this MacBook Pro&#8217;s Photo Booth application&#8217;s webcam &#8230; as much as anything because don&#8217;t want to malign Photo Booth &#8230; see <a target=_blank title='Air Server on Mac Primer Tutorial' href='http:\/\/www.rjmprogramming.com.au\/wordpress\/?p=12711'>Air Server on Mac Primer Tutorial<\/a> regarding my doubts &#8230; 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&#8217;ll flesh out more below with some code and commentary &#8230; like a transcript &#8230; should you decide video is too difficult to decipher (or is too big to download, because, it is big) &#8230;<\/p>\n<ul>\n<li><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Windows\/DotNetFramework\/HelloWorld.ps1_GETME\" title=\"HelloWorld.ps1\">HelloWorld.ps1<\/a> &#8230; contents of in clipboard (via Notepad&#8217;s Edit-&gt;Select All Edit-&gt;Copy) as we enter the tutorial &#8230;<br \/>\n<code><br \/>\n$window = New-Object Windows.Window<br \/>\n$window.Title = $window.Content = \"Hello World of Powershell and WPF together.\"<br \/>\n$window.SizeToContent = \"WidthAndHeight\"<br \/>\n$null = $window.ShowDialog()<br \/>\n<\/code>\n<\/li>\n<li>Windows icon (at bottom left)-&gt;All Programs&gt;Accessories&gt;Windows PowerShell&gt;Windows PowerShell  &#8230; wait to see Powershell prompt<\/li>\n<li>Windows icon (at bottom left)-&gt;All Programs&gt;Accessories&gt;Windows PowerShell&gt;Windows PowerShell ISE &#8230; see a scripting editor and supervisor<\/li>\n<li>Into the top part Edit-&gt;Paste<\/li>\n<li>Click green triangular Run button &#8230; does the right thing &#8230; a dialog box via scripting &#8230; similar to the dialog box in this tutorial&#8217;s picture &#8230; who&#8217;d have believed it?!<\/li>\n<li>File-&gt;Save as&#8230; HelloWorld.ps1<\/li>\n<li>Windows icon-&gt;Run &#8230; enter &#8220;powershell -sta&#8221;<\/li>\n<li>At prompt, type in &#8230; <code>Add-Type -assemblyName PresentationFramework<br \/>\nAdd-Type -assemblyName PresentationCore<br \/>\nAdd-Type -assemblyName WindowsBase<br \/>\n.HelloWorld.ps1<br \/>\n<\/code>\n<\/li>\n<li>&#8230;results in session dialog (with an error) as per &#8230; <code>Windows PowerShell<br \/>\nCopyright (C) 2009 Microsoft Corporation. All rights reserved.<br \/>\nPS C:\\Documents and SettingsOwner&gt; Add-Type -assemblyName PresentationFramework<br \/>\nPS C:\\Documents and SettingsOwner&gt; Add-Type -assemblyName PresentationCore<br \/>\nPS C:\\Documents and SettingsOwner&gt; Add-Type -assemblyName WindowsBase<br \/>\nPS C:\\Documents and SettingsOwner&gt; .HelloWorld.ps1<br \/>\nThe term '.HelloWorld.ps1' is not recognized as the name of a cmdlet, function<br \/>\n, script file, or operable program. Check the spelling of the name, or if a pat<br \/>\nh was included, verify that the path is correct and try again.<br \/>\nAt line:1 char:17<br \/>\n+ .HelloWorld.ps1 &lt;&lt;&lt;&lt;<br \/>\n    + CategoryInfo          : ObjectNotFound: (.HelloWorld.ps1:String) [], Co<br \/>\n   mmandNotFoundException<br \/>\n    + FullyQualifiedErrorId : CommandNotFoundException<br \/>\nPS C:\\Documents and SettingsOwner&gt;<br \/>\n<\/code>\n<\/li>\n<li>In getting information about the error, type in &#8230;<br \/>\n<code>get-help about_signing<br \/>\n<\/code>\n<\/li>\n<li>In solving the permission issue we&#8217;ve plumped (after a false lead trying to alter the &#8220;Block&#8221; on the Properties of the HelloWorld.ps1 file) for &#8230;<br \/>\n<code>get-executionpolicy<br \/>\nset-executionpolicy remotesigned<br \/>\n<\/code>\n<\/li>\n<li>Windows icon (right click)-&gt;Open Windows Explorer &#8230; find where HelloWorld.ps1 is &#8230; right click &#8230; choose Open with&#8230; Powershell &#8230; now this works (as evidenced by the dialog box in this tutorial&#8217;s picture today, as would the &#8220;powershell -sta&#8221; idea work now)<\/li>\n<\/ul>\n<p>Actually, thinking on it, when we say &#8230; <i>&#8220;who&#8217;d have believed it?!&#8221;<\/i> &#8230; perhaps anybody programming in <a target=_blank title='Visual Basic for Applications information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Visual_Basic_for_Applications'>VBA<\/a> and many Internet Explorer web programmers with <a target=_blank title='VBScript information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/VBScript'>VBScript<\/a> 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.<\/p>\n<p>If you are looking for the end result of today&#8217;s work see this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Windows\/DotNetFramework\/Powershell.jpg\">picture<\/a> else wait for the (huge) download of this <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Windows\/DotNetFramework\/Powershell.mov\">video<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d12780' onclick='var dv=document.getElementById(\"d12780\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?tag=.net-framework\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d12780' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you do desktop programming in Windows there is a good chance you do it under the supervision of the .Net Framework &#8230; framework &#8230; chortle, chortle. Given that .Net Framework supervision, in Windows, you can write very sophisticated desktop &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/windows-powershell-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,17,33,37,39],"tags":[44,241,319,549,558,585,782,924,927,976,997,1106,1319,1364,1365,1383,1413,1435,1462],"class_list":["post-12780","post","type-post","status-publish","format-standard","hentry","category-elearning","category-gui","category-software","category-tutorials","category-visual-studio","tag-net-framework","tag-compile","tag-desktop","tag-gui","tag-hello-world","tag-ide","tag-microsoft","tag-photo-booth","tag-photobooth","tag-powershell","tag-programming","tag-scripting","tag-tutorial","tag-vba","tag-vbscript","tag-visual-studio","tag-webcam","tag-windows","tag-wpf"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/12780"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=12780"}],"version-history":[{"count":3,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/12780\/revisions"}],"predecessor-version":[{"id":19492,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/12780\/revisions\/19492"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=12780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=12780"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=12780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}