<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Search results for 'app:weblogs' matching tags 'Windows PowerShell' and 'graphical'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Windows+PowerShell,graphical&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Windows PowerShell' and 'graphical'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>PowerShell Community and the Windows System Administration Tool</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/01/06/powershell-community-and-the-windows-system-administration-tool.aspx</link><pubDate>Fri, 06 Jan 2012 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:13902</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: See how guest blogger, Rich Prescott, leveraged the Windows PowerShell community as he built his popular ArPosh Client System Administration tool.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. We are really starting the new year off correctly. We have another very strong guest blogger today. Rich Prescott, is currently working as an infrastructure architect and Windows engineer at a large media company, with his main areas of focus on automation and Active Directory.&amp;nbsp;The automation responsibilities allow him to work with a wide-range of technologies including virtualization, storage, and monitoring.&amp;nbsp;He started learning Windows PowerShell in 2009 while he was working as a desktop engineer, and he is the lead scripting guy for his organization.&amp;nbsp;He is also a moderator on the &lt;a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/threads" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;&lt;span style="text-decoration:underline;"&gt;,&lt;/span&gt; and was recently rewarded as a Microsoft Community Contributor.&lt;/p&gt;
&lt;p&gt;Blog: &lt;a href="http://blogs.technet.com/controlpanel/blogs/posteditor.aspx/blog.RichPrescott.com"&gt;Engineering Efficiency: Scripts, Tools, and Software New in the IT World&lt;/a&gt;&amp;nbsp;&lt;br /&gt; Twitter: &lt;a href="http://mce_host/controlpanel/blogs/posteditor.aspx/@Rich_Prescott"&gt;@Rich_Prescott&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Take it away Rich&amp;hellip;&lt;/p&gt;
&lt;p&gt;When I first joined the IT world, I was working at the Help desk for a large company. Being new to IT and troubleshooting, I always wondered why there was no single tool for troubleshooting remote computers. I would receive a call about a computer being slow, and I would have to go through four tools to try to diagnose the issue. I began searching for an easy solution, and that is when a coworker introduced me to Windows PowerShell. After reading blog posts from &lt;a href="http://www.scriptingguys.com/blog" target="_blank"&gt;Hey, Scripting Guy!&lt;/a&gt; and the &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/tags/scripting+wife/" target="_blank"&gt;Scripting Wife&lt;/a&gt;, I was writing basic scripts to gather the information that I needed for troubleshooting. This is an example of a basic script I wrote back then.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$PC = &amp;ldquo;PC01&amp;rdquo;&lt;br /&gt; Get-WmiObject Win32_OperatingSystem &amp;ndash;ComputerName $PC&lt;br /&gt; Get-WmiObject Win32_StartupCommand &amp;ndash;ComputerName $PC&lt;br /&gt; Get-WmiObject Win32_Process &amp;ndash;ComputerName $PC&lt;/p&gt;
&lt;p&gt;After the underlying issue was targeted, I needed a way to remediate the issue, such as removing a hung process. This was possible remotely by querying the Win32_Process class on a remote computer, filtering for the process that was causing an issue, and invoking the &lt;b&gt;Terminate&lt;/b&gt; method. Here is an example of using the &lt;b&gt;Terminate&lt;/b&gt; method to stop a process on a remote computer.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;(Get-WmiObject Win32_Process &amp;ndash;ComputerName $PC |&lt;br /&gt; Where-Object {$_.Name &amp;ndash;eq &amp;ldquo;HungProcessName&amp;rdquo;}).Terminate()&lt;/p&gt;
&lt;p&gt;At last, I was able to efficiently troubleshoot issues remotely and even resolve some of them without ever having to leave my desk. As I became more familiar with Windows PowerShell, I thought, &amp;ldquo;Wouldn&amp;rsquo;t it be cool if I could share the efficacy of Windows PowerShell with others, even if they don&amp;rsquo;t know any scripting?&amp;rdquo; After a few months of researching, scripting, and testing GUI creation with Windows PowerShell, the &lt;a href="http://gallery.technet.microsoft.com/a5aff367-7b47-4b50-a2ef-20dcb4bb6d64" target="_blank"&gt;Arposh Client System Administration tool&lt;/a&gt; (ACSA) was released.&lt;/p&gt;
&lt;p&gt;As with any technology that you learn rapidly, when you look back on what you were doing a year ago, you think to yourself, &amp;ldquo;What was I thinking when I wrote that? I could write that in half the code and make it twice as fast.&amp;rdquo; So I set out to find resources to help me rebuild the script from scratch, and I used this opportunity to remove some of the prerequisites, make it compatible with servers, and improve the overall user experience.&lt;/p&gt;
&lt;h3&gt;PowerShellGroup - #PowerShell chat room&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; One of the advantages of using Internet Relay Chat (IRC) is that there are chat rooms for almost any topic you can think of and when you are learning a new technology, having a live discussion can be really helpful. While revamping the ACSA tool, one of the user-experience features that I wanted to add was to give the user the ability to decide which feature sets to use through a configuration file.&lt;/p&gt;
&lt;p&gt;I joined the #PowerShell chat room on &lt;a href="http://powershellgroup.org/virtual/live" target="_blank"&gt;PowerShellGroup.org&lt;/a&gt;, and I asked about an easy way to give users configuration options. Jaykul, a Windows PowerShell MVP, responded with a way to read settings from an XML file. By using the following XML code and three lines of Windows PowerShell, a user is able to set a default domain to connect to when using the GUI. To have the GUI use the current domain of the logged on user, simply update the &lt;b&gt;Enabled&lt;/b&gt; option of the default domain to &amp;ldquo;False&amp;rdquo; in the XML configuration file.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&lt;br /&gt; &amp;nbsp;&amp;lt;Domain Default=&amp;quot;LDAP://DC=RU,DC=lab&amp;quot; Enabled=&amp;quot;True&amp;quot;/&amp;gt;&lt;/p&gt;
&lt;p&gt;In the first line of code, we use &lt;b&gt;Get-Content&lt;/b&gt; on the XML configuration file and specify that it is XML code by using [XML]. We then check to see if the default domain option is enabled, and if so, we set the &lt;b&gt;Domain&lt;/b&gt; variable to what is specified in the XML. If the option is disabled, the GUI sets the &lt;b&gt;Domain&lt;/b&gt; variable to the currently logged on domain.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;[XML]$XML = Get-Content &amp;ldquo;AWSA.Options.xml&amp;rdquo;&lt;br /&gt; &amp;nbsp;if($XML.Domain.Enabled &amp;ndash;eq $True){$Domain = $XML.Domain.Default}&lt;br /&gt; &amp;nbsp;else{$Domain = ([DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()).Name}&lt;/p&gt;
&lt;h3&gt;TechNet Wiki&lt;/h3&gt;
&lt;p&gt;My next task was to make the GUI easy to use, and this meant removing any unnecessary pre-requisites included in the original release. My first stop was the &lt;a href="http://social.technet.microsoft.com/wiki/" target="_blank"&gt;TechNet Wiki&lt;/a&gt; to find a way to query Active Directory for computers without the need to import a Windows PowerShell module that was not freely available on all systems. After a quick search, I landed on a wiki contribution from Richard Mueller, another MVP, for &lt;a href="http://social.technet.microsoft.com/wiki/contents/articles/5392.aspx" target="_blank"&gt;ADSI searches&lt;/a&gt;, which showed me the syntax necessary to build my custom function.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;function Get-RPADComputer{&lt;br /&gt; &amp;nbsp; if($ComputerName -match &amp;quot;.&amp;quot;){$ComputerName = $ComputerName.Split(&amp;#39;.&amp;#39;)[0]}&lt;br /&gt; &amp;nbsp; $searcher=[adsisearcher]&amp;quot;(&amp;amp;(objectClass=computer)(name=$ComputerName*))&amp;quot;&lt;br /&gt; &amp;nbsp; $Properties = $XML.Options.Search.Property&lt;br /&gt; &amp;nbsp; $searcher.PropertiesToLoad.AddRange($Properties) &lt;br /&gt; &amp;nbsp;&amp;nbsp;$searcher.FindAll()&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;This function checks the &lt;i&gt;$ComputerName &lt;/i&gt;parameter that is specified in the textbox of the GUI, and if a fully qualified domain name (FQDN) is specified, it translates it to a short name. It then creates a query that will search for any computers that match the new &lt;i&gt;$ComputerName&lt;/i&gt; variable. The third line reads a list of properties that the user specifies in the XML settings file and adds them to the list of properties to load. The final line of the function executes the query and returns the results.&lt;/p&gt;
&lt;h3&gt;TechNet forums&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; After adding in the ability to set a default domain when launching the GUI, the user needed a way to change domains without having to edit the XML file and relaunch the script. I was not familiar enough with the ADSI scripting techniques that I found on the TechNet Wiki, and I decided to head over to the &lt;a href="http://social.technet.microsoft.com/Forums/en-us/ITCG/threads" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt; on the &lt;a href="http://social.technet.microsoft.com/Forums/en-us/categories/" target="_blank"&gt;TechNet Forums&lt;/a&gt; and ask for some assistance.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://social.technet.microsoft.com/Forums/en-US/ITCG/thread/5ff7b8c0-9c32-44a3-8cc9-8859cd3dc691/" target="_blank"&gt;I posted my question&lt;/a&gt; with some examples of the input and output that I wanted, and within four hours, I received multiple responses from the community. And what do you know&amp;mdash;Richard Mueller again came to the rescue with a way to prompt for a domain and then convert the response into the LDAP path for that domain. By slightly tweaking his code, I was able to add the ability to search alternate domains to my custom Active Directory computer search function.&lt;/p&gt;
&lt;h3&gt;TechNet ScriptCenter&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; There are many new features in this update of the GUI, but I want to highlight one that many administrators will find very useful and sigh at the mention of: local administrator rights. Every system administrator has received a request along the lines of, &amp;ldquo;I need to install XYZ software right now!&amp;rdquo; or &amp;ldquo;I am using VPN from home, and I need to add a local printer.&amp;rdquo; One way to get around this (not always the best way) is to grant the user temporary local administrator rights. To find out how to do this the Windows PowerShell way, I headed over to the &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/" target="_blank"&gt;TechNet ScriptCenter Repository&lt;/a&gt; to search for some examples.&lt;/p&gt;
&lt;p&gt;Using the &lt;b&gt;Categories&lt;/b&gt; listing in the left pane, I drilled down into &lt;b&gt;Local Account Management&lt;/b&gt;, and I immediately saw what I was looking for: &lt;a href="http://gallery.technet.microsoft.com/scriptcenter/f75801e7-169a-4737-952c-1341abea5823" target="_blank"&gt;Local User Management Module&lt;/a&gt;. I clicked through to the details page and looked through the included functions. I was in luck! By using ADSI code in the &lt;b&gt;Set-LocalGroup&lt;/b&gt; function, I morphed it into my own function as shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;Function Add-LocalAdmin {&lt;br /&gt; &amp;nbsp;&amp;nbsp;[System.Reflection.Assembly]::LoadWithPartialName(&amp;#39;Microsoft.VisualBasic&amp;#39;) | Out-Null&lt;br /&gt; &amp;nbsp;&amp;nbsp;$Input = [Microsoft.VisualBasic.Interaction]::InputBox(&amp;quot;Enter a username to add (Domain\Username)&amp;quot;, &amp;quot;Add Local Admin&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt; &amp;nbsp;&amp;nbsp;$Group = [ADSI](&amp;quot;WinNT://&amp;quot; + $ComputerName + &amp;quot;/Administrators, group&amp;quot;)&lt;br /&gt; &amp;nbsp;&amp;nbsp;$Group.Add(&amp;quot;WinNT://&amp;quot; +$Input.Replace(&amp;lsquo;\&amp;rsquo;,&amp;rsquo;/&amp;rsquo;)&lt;br /&gt; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;The first line of the function loads the Visual Basic assembly; this allows me to create a custom input box, which prompts the user for the username to add to the local administrators group and then stores it in the &lt;b&gt;$Input&lt;/b&gt; variable. The function then binds to the Administrators group on the remote computer using ADSI. Now we call the &lt;b&gt;Add&lt;/b&gt; method of ADSI to add the desired user account to the administrators group. But there is a snag, the username is specified as Domain\Username, whereas ADSI requires a forward slash. To get around this, we use the &lt;b&gt;Replace&lt;/b&gt; method to turn the back slash into a forward slash.&lt;/p&gt;
&lt;h3&gt;Arposh Windows System Administration tool&lt;/h3&gt;
&lt;p&gt;&lt;br /&gt; Whether you are new to Windows PowerShell and only need a simple script to get you going or you are a Windows PowerShell guru and need a nudge in the right direction, there are numerous resources for everyone. Thanks to all of these resources, I was able to take a simple GUI that I created for myself to make tasks easier and improve it enough to where the Windows PowerShell community would also find it useful. Without further ado, here is the &lt;a href="http://gallery.technet.microsoft.com/Arposh-Windows-System-a1beb102" target="_blank"&gt;Arposh Windows System Administration tool&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3666.hsg_2D00_1_2D00_6_2D00_12_2D00_1.jpg"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3666.hsg_2D00_1_2D00_6_2D00_12_2D00_1.jpg" alt="Image of Arposh" title="Image of Arposh" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;~Rich&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3473467" width="1" height="1" alt="" /&gt;</description></item><item><title>Create a Simple Graphical Interface for a PowerShell Script</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/07/24/create-a-simple-graphical-interface-for-a-powershell-script.aspx</link><pubDate>Sun, 24 Jul 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:11537</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Learn how to create a simple graphical interface for a Windows PowerShell script.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size:large;"&gt;&lt;strong&gt;Weekend Scripter: Extending PowerShell to the GUI with Sapien Tools&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy Ed Wilson here. Sean Kearney joins us again today as our guest blogger. Read more about Sean and &lt;a href="http://blogs.technet.com/search/searchresults.aspx?q=kearney&amp;amp;sections=7618&amp;amp;sort=date+desc&amp;amp;PageIndex=1"&gt;his previous blog posts&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Here is Sean!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;While playing with Sapien Primal Forms, I was thinking, &amp;ldquo;If you never used this, how could you figure out how to make it work with Windows PowerShell?&amp;rdquo; Stop falling down on your faces. I don&amp;rsquo;t hate the GUI. Windows PowerShell is not about shutting down one interface for another. It&amp;rsquo;s about enabling the tools you have for the best purpose to meet your job.&lt;/p&gt;
&lt;p&gt;Think about it. There is absolutely nothing wrong with Active Directory Users and Computers. It works. It&amp;rsquo;s a great generic interface that applies to multiple needs and works well across a variety of platforms. But it isn&amp;rsquo;t necessarily the best interface for a specific job. But each one of us has a need that it may be too much for. A simple example is the person that works the Help Desk and just unlocks user accounts. (It&amp;#39;s not the only thing they do of course, but just an example.) In Active Directory they would have to find the account, pull up the properties of the account, reset the unlock field, and maybe reset the password.&lt;/p&gt;
&lt;p&gt;You get the idea. When really all I want to do is type in the name and have the job done. The computer should ask me want I need to do. The workflow for unlocking an account would typically be this:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;WHO do you want to Unlock?&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Unlock the Account&lt;/p&gt;
&lt;p&gt;OR&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;WHO do want to Reset?&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;WHAT will their new password be?&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Unlock the Account&lt;/p&gt;
&lt;p&gt;So in Windows PowerShell, I might do something like this for an unlock user script:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$USERFIRSTNAME=READ-HOST &amp;lsquo;First Name&amp;rsquo; &lt;br /&gt;$USERLASTNAME=READ-HOST &amp;lsquo;Last Name&amp;rsquo; &lt;br /&gt;GET-QADUSER &amp;ndash;FirstName $USERFIRSTNAME &amp;ndash;LastName $USERLASTNAME | UNLOCK-QADUSER&lt;/p&gt;
&lt;p&gt;Or if I knew the structure of the SAM account, I could just key this in:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;UNLOCK-QADUSER &amp;lsquo;SAMAccountName&amp;rsquo;&lt;/p&gt;
&lt;p&gt;This is obviously far more efficient that searching Active Directory, finding the darn button, clicking it, and so on. With little difficulty, I could pipe in a list of users and unlock them.&lt;/p&gt;
&lt;p&gt;So great, the administrator is happy. So how does this help our your local Help Desk?&lt;/p&gt;
&lt;p&gt;With Sapien Primal Forms Community Edition, you can create a basic GUI to extend that Windows Powershell script into a GUI interface for that Help Desk so that you don&amp;rsquo;t need to retrain them. You can provision an interface to meet their job needs without incurring heavy development costs.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a bonus too you may not realize: the generated Windows PowerShell script from Sapien is a stand-alone script. All it does when you&amp;rsquo;re done is generate the needed code within a Windows PowerShell script to call up forms in Windows. All features of those forms are fully supported because they are features of the GUI.&lt;/p&gt;
&lt;p&gt;So here&amp;rsquo;s a simple form.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3326.WES_2D00_7_2D00_24_2D00_11_2D00_1.jpg"&gt;&lt;img style="border:0px;" title="Image of simple form" alt="Image of simple form" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3326.WES_2D00_7_2D00_24_2D00_11_2D00_1.jpg" width="514" height="156" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The Windows PowerShell script generated by Sapien to do this is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;--------------------------------------HELPDESK.PS1-----------------------------------------------&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#Generated Form Function &lt;br /&gt;function GenerateForm { &lt;br /&gt;######################################################################## &lt;br /&gt;# Code Generated By: SAPIEN Technologies PrimalForms (Community Edition) v1.0.8.0 &lt;br /&gt;# Generated On: 7/3/2011 11:35 AM &lt;br /&gt;# Generated By: sean.kearney &lt;br /&gt;########################################################################&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#region Import the Assemblies &lt;br /&gt;[reflection.assembly]::loadwithpartialname(&amp;quot;System.Windows.Forms&amp;quot;) | Out-Null &lt;br /&gt;[reflection.assembly]::loadwithpartialname(&amp;quot;System.Drawing&amp;quot;) | Out-Null &lt;br /&gt;#endregion&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#region Generated Form Objects &lt;br /&gt;$HelpDeskForm = New-Object System.Windows.Forms.Form &lt;br /&gt;$UnlockAccountButton = New-Object System.Windows.Forms.Button &lt;br /&gt;$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState &lt;br /&gt;#endregion Generated Form Objects&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#---------------------------------------------- &lt;br /&gt;#Generated Event Script Blocks &lt;br /&gt;#---------------------------------------------- &lt;br /&gt;#Provide Custom Code for events specified in PrimalForms. &lt;br /&gt;$handler_UnlockAccountButton_Click= &lt;br /&gt;{ &lt;br /&gt;#TODO: Place custom script here&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$OnLoadForm_StateCorrection= &lt;br /&gt;{#Correct the initial state of the form to prevent the .Net maximized form issue &lt;br /&gt;$HelpDeskForm.WindowState = $InitialFormWindowState &lt;br /&gt;}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#---------------------------------------------- &lt;br /&gt;#region Generated Form Code &lt;br /&gt;$HelpDeskForm.Text = &amp;quot;Our Help Desk&amp;quot; &lt;br /&gt;$HelpDeskForm.Name = &amp;quot;HelpDeskForm&amp;quot; &lt;br /&gt;$HelpDeskForm.DataBindings.DefaultDataSourceUpdateMode = 0 &lt;br /&gt;$System_Drawing_Size = New-Object System.Drawing.Size &lt;br /&gt;$System_Drawing_Size.Width = 265 &lt;br /&gt;$System_Drawing_Size.Height = 55 &lt;br /&gt;$HelpDeskForm.ClientSize = $System_Drawing_Size&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$UnlockAccountButton.TabIndex = 0 &lt;br /&gt;$UnlockAccountButton.Name = &amp;quot;UnlockAccountButton&amp;quot; &lt;br /&gt;$System_Drawing_Size = New-Object System.Drawing.Size &lt;br /&gt;$System_Drawing_Size.Width = 240 &lt;br /&gt;$System_Drawing_Size.Height = 23 &lt;br /&gt;$UnlockAccountButton.Size = $System_Drawing_Size &lt;br /&gt;$UnlockAccountButton.UseVisualStyleBackColor = $True&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$UnlockAccountButton.Text = &amp;quot;UNLOCK Account&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$System_Drawing_Point = New-Object System.Drawing.Point &lt;br /&gt;$System_Drawing_Point.X = 13 &lt;br /&gt;$System_Drawing_Point.Y = 13 &lt;br /&gt;$UnlockAccountButton.Location = $System_Drawing_Point &lt;br /&gt;$UnlockAccountButton.DataBindings.DefaultDataSourceUpdateMode = 0 &lt;br /&gt;$UnlockAccountButton.add_Click($handler_UnlockAccountButton_Click)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$HelpDeskForm.Controls.Add($UnlockAccountButton)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#endregion Generated Form Code&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#Save the initial state of the form &lt;br /&gt;$InitialFormWindowState = $HelpDeskForm.WindowState &lt;br /&gt;#Init the OnLoad event to correct the initial state of the form &lt;br /&gt;$HelpDeskForm.add_Load($OnLoadForm_StateCorrection) &lt;br /&gt;#Show the Form &lt;br /&gt;$HelpDeskForm.ShowDialog()| Out-Null&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} #End Function&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#Call the Function &lt;br /&gt;GenerateForm &lt;br /&gt;--------------------------------------HELPDESK.PS1-----------------------------------------------&lt;/p&gt;
&lt;p&gt;The first time I looked at one of these, I almost fell down! So much code! But most of it is actually comments and object generation. Just look for the spot near the top where it states:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#TODO: Place custom script here.&lt;/p&gt;
&lt;p&gt;If you look above, you&amp;rsquo;ll see it says:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$handler_UnlockAccountButton_Click=&lt;/p&gt;
&lt;p&gt;This is the portion generated for WPF that says &amp;ldquo;When I click this, the code gets run&amp;rdquo;. You could happily click it, and it would do nothing, because there is no code attached to the button. But we can easily create some new code that does an account unlock. We can take this same block from before and attach it to the button:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$handler_UnlockAccountButton_Click= &lt;br /&gt;{ &lt;br /&gt;#TODO: Place custom script here&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$USERFIRSTNAME=READ-HOST &amp;lsquo;First Name&amp;rsquo; &lt;br /&gt;$USERLASTNAME=READ-HOST &amp;lsquo;Last Name&amp;rsquo; &lt;br /&gt;GET-QADUSER &amp;ndash;FirstName $FIRSTNAME &amp;ndash;LastName $LASTNAME | UNLOCK-QADUSER&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;}&lt;/p&gt;
&lt;p&gt;Now this will try to work but can&amp;rsquo;t from a form as it will try to get in the console. What we&amp;rsquo;ll have to do is create another form or maybe add some input fields to this one. With Primal Tools, I&amp;rsquo;ve added two parts to the form: two text boxes and two labels. I&amp;rsquo;ve tried to give them some meaningful descriptive names such as &lt;strong&gt;FirstNameLabel&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1220.WES_2D00_7_2D00_24_2D00_11_2D00_2.jpg"&gt;&lt;img style="border:0px;" title="Image of simple form with two labeled text boxes" alt="Image of simple form with two labeled text boxes" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1220.WES_2D00_7_2D00_24_2D00_11_2D00_2.jpg" width="507" height="227" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I could reproduce the code but the important stuff is near the top where you see the objects defined as variables:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#region Generated Form Objects &lt;br /&gt;$HelpDeskForm = New-Object System.Windows.Forms.Form &lt;br /&gt;$LastnameLabel = New-Object System.Windows.Forms.Label &lt;br /&gt;$FirstNameLabel = New-Object System.Windows.Forms.Label &lt;br /&gt;$LASTNAME = New-Object System.Windows.Forms.TextBox &lt;br /&gt;$FIRSTNAME = New-Object System.Windows.Forms.TextBox &lt;br /&gt;$UnlockAccountButton = New-Object System.Windows.Forms.Button &lt;br /&gt;$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState &lt;br /&gt;#endregion Generated Form Objects&lt;/p&gt;
&lt;p&gt;The rest of it is the form calling up and adding the objects to the form. Now look at the bottom of your script where it says &lt;strong&gt;GenerateForm&lt;/strong&gt;. Everything up to but not including that is a function being defined. This is important to know because if I change the function so that it&amp;rsquo;s seen in the global context and don&amp;rsquo;t run it from the script, I can now just call it from the command line.&lt;/p&gt;
&lt;p&gt;Knowing this is important. If you put it in the global context and switch your variables to global (for testing purposes), you can easily pull up the properties of those variables to see how your data is stored.&lt;/p&gt;
&lt;p&gt;So to figure out where the information could be accessed on the &lt;strong&gt;$FIRSTNAME&lt;/strong&gt; text box, I switched both the defined function at the top called &lt;strong&gt;GenerateForm&lt;/strong&gt; and my &lt;strong&gt;$FIRSTNAME&lt;/strong&gt; variable to global. I then removed the &lt;strong&gt;GenerateForm&lt;/strong&gt; from the bottom of the script:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function global:GenerateForm {.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;#region Generated Form Objects &lt;br /&gt;$HelpDeskForm = New-Object System.Windows.Forms.Form &lt;br /&gt;$LastnameLabel = New-Object System.Windows.Forms.Label &lt;br /&gt;$FirstNameLabel = New-Object System.Windows.Forms.Label &lt;br /&gt;$LASTNAME = New-Object System.Windows.Forms.TextBox &lt;br /&gt;&lt;span style="text-decoration:underline;"&gt;$GLOBAL:FIRSTNAME = New-Object System.Windows.Forms.TextBox &lt;br /&gt;&lt;/span&gt;$UnlockAccountButton = New-Object System.Windows.Forms.Button &lt;br /&gt;$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState &lt;br /&gt;#endregion Generated Form Objects&lt;/p&gt;
&lt;p&gt;With this done, I just run&amp;hellip;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;GENERATEFORM&lt;/p&gt;
&lt;p&gt;&amp;hellip;from the Windows PowerShell console and key in some stuff such as is shown in the following figure.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5187.WES_2D00_7_2D00_24_2D00_11_2D00_3.jpg"&gt;&lt;img style="border:0px;" title="Image of form being filled in with Sean&amp;#39;s real name" alt="Image of form being filled in with Sean&amp;#39;s real name" src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/5187.WES_2D00_7_2D00_24_2D00_11_2D00_3.jpg" width="512" height="209" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And then afterward, I&amp;nbsp;close the form.&lt;/p&gt;
&lt;p&gt;To reveal all the properties and their values, I can now type:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$FIRSTNAME | Format-List&lt;/p&gt;
&lt;p&gt;I can now see there is a field called &lt;b&gt;Text&lt;/b&gt;, which has the value I entered in for &lt;b&gt;$FIRSTNAME&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;With this knowledge I can now extend the values I entered there into my &lt;b&gt;Unlock Account&lt;/b&gt; button by changing the Read-Host to simply point to the values in &lt;b&gt;$FIRSTNAME.TEXT&lt;/b&gt; and &lt;b&gt;$LASTNAME.TEXT&lt;/b&gt;:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$handler_UnlockAccountButton_Click= &lt;br /&gt;{ &lt;br /&gt;#TODO: Place custom script here &lt;br /&gt;$USERFIRSTNAME=$FIRSTNAME.TEXT &lt;br /&gt;$USERLASTNAME=$LASTNAME.TEXT &lt;br /&gt;GET-QADUSER &amp;ndash;FirstName $USERFIRSTNAME &amp;ndash;LastName $USERLASTNAME | UNLOCK-QADUSER &lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;We now remove &lt;b&gt;GLOBAL:&lt;/b&gt; before &lt;b&gt;GenerateForm&lt;/b&gt; and &lt;b&gt;$FIRSTNAME&lt;/b&gt;, and resave the script.&lt;/p&gt;
&lt;p&gt;Now running the &lt;b&gt;GenerateForm&lt;/b&gt; will produce our new &lt;b&gt;UNLOCK USER&lt;/b&gt; piece for the Help Desk and allow them to just type in the first and last name to unlock a user.&lt;/p&gt;
&lt;p&gt;We can of course go much further with this such as setting up some confirmations, maybe closing the Window, verifying we found the proper user account. But the point of all this is to give you some baby steps and with that maybe you can build something a lot more powerful.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks Sean. That wraps up another weekend.&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3440408" width="1" height="1" alt="" /&gt;</description></item><item><title>Use ShowUi to Easily Create Graphical Interfaces for PowerShell</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/07/10/use-showui-to-easily-create-graphical-interfaces-for-powershell.aspx</link><pubDate>Sun, 10 Jul 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:11307</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;: Use ShowUi, a free Windows PowerShell module, to simplify creating graphical interfaces for scripts.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy Ed Wilson here. Today, I have a guest article from my good friend James Brundage. Here is a little bit about him. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;James Brundage is the founder of &lt;a href="http://www.start-automating.com/"&gt;Start-Automating&lt;/a&gt;, a company dedicated to saving people time and money by helping them automate. Start-Automating offers Windows PowerShell training and custom Windows PowerShell and .NET Framework development. James formerly worked on the Windows PowerShell team at Microsoft. You can follow James on Twitter (@jamesbru) or on the &lt;a href="http://blog.start-automating.com/"&gt;Start-Automating company blog&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Take it away, James!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Some people say I love Windows PowerShell a little too much.&lt;/p&gt;
&lt;p&gt;I strongly believe that a script a day keeps Dr. Scripto away. I easily spend more time scripting with PowerShell than any other recreation activity (except maybe Xbox), and I take any statement along the lines of &amp;ldquo;you can&amp;rsquo;t do that in Windows PowerShell&amp;rdquo; as a challenge.&lt;/p&gt;
&lt;p&gt;Today, I&amp;rsquo;m going to showcase an answer to one of those &amp;ldquo;you can&amp;rsquo;t do that in Windows PowerShell&amp;rdquo; lines.&lt;/p&gt;
&lt;p&gt;An astoundingly large number of people don&amp;rsquo;t know that you can write user interfaces in Windows PowerShell. Some small technical changes in Windows PowerShell 2.0 enabled scripting of a really cool UI platform called &lt;a href="http://en.wikipedia.org/wiki/Windows_Presentation_Foundation"&gt;Windows Presentation Foundation&lt;/a&gt; (WPF).&lt;/p&gt;
&lt;p&gt;In June 2011, scripting WPF reached a whole new level of easy with the release of ShowUI. ShowUI is a Windows PowerShell module that makes it simple to write UI in Windows PowerShell with WPF. You can download ShowUI at &lt;a href="http://showui.codeplex.com/"&gt;http://showui.codeplex.com/&lt;/a&gt;. Now, not only can you write user interfaces in Windows PowerShell, but they&amp;rsquo;re almost always a lot shorter.&lt;/p&gt;
&lt;p&gt;In This Weekend Scripter article, I&amp;rsquo;ll show and explain a fun sample: &lt;a href="http://www.youtube.com/watch?v=JcLVbNnAm9A&amp;amp;feature=related"&gt;How to Write a Drag-and-Drop Video Player in 12 Lines of Script&lt;/a&gt;. Here&amp;rsquo;s the code:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;New-Window -AllowDrop -On_Drop {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $videoPlayer.Source = @($_.Data.GetFileDropList())[0]&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $videoPlayer.Play()&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} -On_Loaded {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $videoPlayer.Source = Get-ChildItem -Path &amp;quot;$env:Public\Videos\Sample Videos&amp;quot; -Filter *.wmv |&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Get-Random | Select-Object -ExpandProperty Fullname&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $videoPlayer.Play()&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} -On_Closing {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $videoPlayer.Stop()&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} -Content {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; New-MediaElement -Name VideoPlayer -LoadedBehavior Manual&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} &amp;ndash;asjob&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s a pretty simple app. I create a window, and I allow it to accept dropped items. Whenever an item is dropped (&lt;b&gt;On_Drop&lt;/b&gt;), I look into that items data and get out the list of files. Then I select the first one, and make the video player&amp;rsquo;s source that item. Then, I start up the video player.&lt;/p&gt;
&lt;p&gt;Whenever a window is loaded, I go find all the sample videos, pick a random one, and make that the video player&amp;rsquo;s source. I then start the video player. Whenever the window is closing, I make sure to stop the video player as well, or else the media actually keeps playing in an invisible window. The window only has a little bit of content. That content is a media element called &lt;b&gt;VideoPlayer&lt;/b&gt;. This &lt;b&gt;MediaElement&lt;/b&gt; is what&amp;rsquo;s providing the value for &lt;b&gt;$videoplayer&lt;/b&gt; everywhere in the script. Because we want to be able to stop and play the video manually, I set &lt;b&gt;LoadedBehavior&lt;/b&gt; to &lt;b&gt;Manual&lt;/b&gt;. To make sure that I can watch the videos and script at the same time, I launch my UI in the background with &lt;b&gt;&amp;ndash;AsJob&lt;/b&gt;.&lt;/p&gt;
&lt;p&gt;ShowUI lets you build richer solutions than you ever thought possible with Windows PowerShell. Download it for yourself at &lt;a href="http://showui.codeplex.com/"&gt;http://showui.codeplex.com/&lt;/a&gt;, and keep watching &lt;a href="http://www.youtube.com/StartAutomating"&gt;our YouTube channel&lt;/a&gt; for more videos. And the next time a colleague of yours doubts the power of Windows PowerShell, just say:&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Hey, I&amp;rsquo;ve got a little video to show you.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Splatting and ShowUI&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Splatting is a nifty technique that lets you use a hash table as the input for your scripts or cmdlets. I cover this in greater detail in A Series on Splatting (&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/18/use-splatting-to-simplify-your-powershell-scripts.aspx"&gt;Part 1&lt;/a&gt;, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/19/automatically-create-custom-powershell-functions.aspx"&gt;Part 2&lt;/a&gt;, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/20/use-powershell-to-combine-multiple-commands-for-ease-of-use.aspx"&gt;Part 3&lt;/a&gt;, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/21/packaging-net-framework-classes-into-windows-powershell-functions.aspx"&gt;Part 4&lt;/a&gt;, &lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/10/22/make-windows-powershell-your-web-client.aspx"&gt;Part 5&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;This example shows how we can make a frontend for the world&amp;rsquo;s simplest function: &lt;b&gt;Out-LastNameFirstName&lt;/b&gt;. Watch the &lt;a href="http://www.youtube.com/watch?v=HM2vc5KBKqk"&gt;YouTube video&lt;/a&gt;.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Import-Module ShowUI&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;function Out-LastNameFirstName&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;{&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; param($firstName,$lastName)&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;quot;$lastName, $firstName&amp;quot;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$in = New-UniformGrid&amp;nbsp; -Columns 2 -ControlName Get-FirstAndLastName -Children {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;First Name&amp;#39;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; New-TextBox -Name FirstName&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39;Last Name&amp;#39;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; New-TextBox -Name LastName&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;#39; &amp;#39;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;New-Button &amp;quot;OK&amp;quot; -IsDefault -On_Click {&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $parent | Set-UIValue -passThru | Close-Control&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;} -show&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;Out-LastNameFirstName @in&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The function is simple enough. &lt;b&gt;Out-LastAndFirstName&lt;/b&gt; will simply print out a &lt;b&gt;firstName&lt;/b&gt; and &lt;b&gt;lastName&lt;/b&gt; packed together in &lt;b&gt;lastName&lt;/b&gt;, &lt;b&gt;firstName&lt;/b&gt; format. The UI is also really simple, because of the magic of ShowUI.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;$in&lt;/b&gt; will set the window&amp;rsquo;s value when we close. A &lt;b&gt;UniformGrid&lt;/b&gt; is a control that will automatically put items in a uniformly arranged grid. By giving the grid two columns, I can guarantee that the odd-numbered items go on the left and the even-numbered items go on the right.&lt;/p&gt;
&lt;p&gt;The grid has a &lt;i&gt;ControlName&lt;/i&gt;: &lt;b&gt;Get-FirstAndLastName&lt;/b&gt;. &lt;i&gt;&amp;ndash;ControlName&lt;/i&gt; is a parameter in ShowUI that lets you anchor all of the values to a particular part of the UI. &lt;i&gt;&amp;ndash;ControlName&lt;/i&gt; helps determine which variables are there in your event handler, and where the UI will get values.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&amp;lsquo;First Name&amp;rsquo;&lt;/b&gt; is just a string, and, if you put a string inside a collection in ShowUI, it will automatically try to turn it into a label. The text box comes right after it, and will appear on the right side. By giving the text box a name, two things happen:&amp;nbsp;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A variable &lt;b&gt;$FirstName&lt;/b&gt; will appear in all of the event handlers pointing to that object.&lt;/li&gt;
&lt;li&gt;Whenever we go to output the value of &lt;b&gt;Get-FirstAndLastName&lt;/b&gt;, it will create an entry in a hash table which contains the text in the text box.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &amp;nbsp;&lt;b&gt;&amp;lsquo; &amp;nbsp;&amp;lsquo;&lt;/b&gt; simply forces a space. This just helps alignment within the uniform grid. The &lt;b&gt;OK&lt;/b&gt; button is where the magic is. When it is clicked, the automatic variable &lt;b&gt;$parent&lt;/b&gt; (which points to the nearest &lt;b&gt;&amp;ndash;ControlName&lt;/b&gt;) is piped into a command &lt;b&gt;Set-UIValue&lt;/b&gt;. At this point, &lt;b&gt;Set-UIValue&lt;/b&gt; creates a value for the control based on what was typed in the text boxes.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks again to James Brundage! I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3440392" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Solution for 2011 Scripting Games Advanced Event 8: Use PowerShell to Resize Images and to Remove EXIF Data</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/04/27/expert-solution-for-2011-scripting-games-advanced-event-8-use-powershell-to-resize-images-and-to-remove-exif-data.aspx</link><pubDate>Wed, 27 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:10137</guid><dc:creator>Anonymous</dc:creator><description>Summary : Microsoft PowerShell MVP, Marc van Orsouw, resizes images and removes EXIF metadata while solving 2011 Scripting Games Advanced Event 8. Microsoft Scripting Guy, Ed Wilson, here. Marc van Orsouw (MoW) is our expert commentator for Advanced Event...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/27/expert-solution-for-2011-scripting-games-advanced-event-8-use-powershell-to-resize-images-and-to-remove-exif-data.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3423128" width="1" height="1" alt="" /&gt;</description></item><item><title>The 2011 Scripting Games Advanced Event 8: Use PowerShell to Remove Metadata and Resize Images</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/04/13/the-2011-scripting-games-advanced-event-8-use-powershell-to-remove-metadata-and-resize-images.aspx</link><pubDate>Wed, 13 Apr 2011 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9966</guid><dc:creator>Anonymous</dc:creator><description>Summary : Advanced Event 8 in 2011 Scripting Games uses Windows PowerShell to remove metadata from image files and to resize those images. About this event Division Advanced Date of Event 4/13/2011 12:15 AM Due Date 4/20/2011 12:15 AM Event scenario You...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/04/13/the-2011-scripting-games-advanced-event-8-use-powershell-to-remove-metadata-and-resize-images.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3416888" width="1" height="1" alt="" /&gt;</description></item><item><title>Use PowerShell to Add Commands to the Windows Explorer Command Bar</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/02/27/use-powershell-to-add-commands-to-the-windows-explorer-command-bar.aspx</link><pubDate>Sun, 27 Feb 2011 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:9508</guid><dc:creator>Anonymous</dc:creator><description>Summary : Learn how to use Windows PowerShell to add commands to the Windows Explorer command bar in Windows 7 and Windows Vista. Weekend Scripter Microsoft Scripting Guy, Ed Wilson, here. Did you ever have one of those times when a seemingly simple project...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/02/27/use-powershell-to-add-commands-to-the-windows-explorer-command-bar.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3390340" width="1" height="1" alt="" /&gt;</description></item><item><title>Draw Boxes and Lines in the Windows PowerShell Console Host</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2010/09/19/draw-boxes-and-lines-in-the-windows-powershell-console-host.aspx</link><pubDate>Sun, 19 Sep 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:7649</guid><dc:creator>Anonymous</dc:creator><description>Summary : Microsoft MVP Sean Kearney shows how to draw boxes and lines in the Windows PowerShell console while scripting three reusable functions. Microsoft Scripting Guy Ed Wilson here. Just when I thought it was safe to open my email, I get a tweet...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/19/draw-boxes-and-lines-in-the-windows-powershell-console-host.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3354796" width="1" height="1" alt="" /&gt;</description></item><item><title>Hey, Scripting Guy! How Can I Use the Windows Forms TreeView Control?</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2010/06/15/hey-scripting-guy-how-can-i-use-the-windows-forms-treeview-control.aspx</link><pubDate>Tue, 15 Jun 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:6845</guid><dc:creator>Anonymous</dc:creator><description>Today we have a guest article by Ravikanth who works at Dell, Inc., as a lead engineer in the SharePoint Solutions Team. He loves automation and is a Windows PowerShell fanatic. He writes regularly on his blog about topics related to Windows PowerShell...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/06/15/hey-scripting-guy-how-can-i-use-the-windows-forms-treeview-control.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3334755" width="1" height="1" alt="" /&gt;</description></item><item><title>Expert Solutions: Advanced Event 7 of the 2010 Scripting Games</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2010/05/25/expert-solutions-advanced-event-7-of-the-2010-scripting-games.aspx</link><pubDate>Tue, 25 May 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:6674</guid><dc:creator>Anonymous</dc:creator><description>( Note : These solutions were written for Advanced Event 7 of the 2010 Scripting Games .) Advanced Event 7 (Windows PowerShell) James Brundage is a former software developer engineer in testing for Microsoft. He has been a frequent poster on the Windows...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2010/05/25/expert-solutions-advanced-event-7-of-the-2010-scripting-games.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3333143" width="1" height="1" alt="" /&gt;</description></item><item><title>Hey, Scripting Guy! Quick-Hits Friday: The Scripting Guys Respond to a Bunch of Questions (5/14/10)</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2010/05/14/hey-scripting-guy-quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-5-14-10.aspx</link><pubDate>Fri, 14 May 2010 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:5604</guid><dc:creator>Anonymous</dc:creator><description>In this post : How Can I Use the Ver Command in Windows PowerShell? What Do These Numbers Mean That Are Returned by This WMI Class? How Can I Change the Color of Text Displayed in the Windows PowerShell Console? How Can I Get the User Name That Runs Services...(&lt;a href="http://blogs.technet.com/heyscriptingguy/archive/2010/05/14/Hey-Scripting-Guy-Quick-Hits-Friday-The-Scripting-Guys-Respond-to-a-Bunch-of-Questions-May-14-2010.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3331445" width="1" height="1" alt="" /&gt;</description></item></channel></rss>