{"id":10222,"date":"2015-11-12T09:00:53","date_gmt":"2015-11-12T17:00:53","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=10222"},"modified":"2015-11-10T09:19:05","modified_gmt":"2015-11-10T17:19:05","slug":"powershellget-gui-part-2","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2015\/11\/12\/powershellget-gui-part-2\/","title":{"rendered":"PowerShellGet-GUI Part 2"},"content":{"rendered":"<p>Continuing on from where we left off in our last blog post entitled &#8220;<a href=\"https:\/\/wp.me\/p3tXTf-2E9\">PowerShellGet-GUI part <\/a>1&#8243;, let us examine some of the other features of the PowerShell Get GUI application.<\/p>\n<p>With our list successfully loaded with PowerShell Gallery modules, the user can take several actions:<\/p>\n<ol>\n<li>Select a module to inspect it&#8217;s properties<\/li>\n<li>Select a non-installed module to install it<\/li>\n<li>Select an installed module to uninstall it<\/li>\n<\/ol>\n<p><strong>Case 1<\/strong><\/p>\n<div id=\"attachment_10223\" style=\"width: 1283px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-1.54.27-PM.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-10223\" class=\"wp-image-10223 size-full\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-1.54.27-PM.png\" alt=\"Screen Shot 2015-11-03 at 1.54.27 PM\" width=\"1273\" height=\"577\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-1.54.27-PM.png 1273w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-1.54.27-PM-300x136.png 300w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-1.54.27-PM-1024x464.png 1024w\" sizes=\"auto, (max-width: 1273px) 100vw, 1273px\" \/><\/a><p id=\"caption-attachment-10223\" class=\"wp-caption-text\">Figure 1<\/p><\/div>\n<p>When the user clicks on an item in the list, the listview_ItemSelectionChanged event fires and is handled by our $lvModules_ItemSelectionChanged event handler seen in Figure 1 above. If an item has been selected, we first save the contents of the .Tag property to a local variable, $module. If you remember back to the previous post, when we filled our list we stored the actual module in the .Tag property for later access. <a href=\"https:\/\/www.sapien.com\/blog\/2013\/05\/23\/spotlight-on-controls-the-versatile-tag-property\/\">See this article<\/a> for more detailed information about the TAG property.<\/p>\n<p>We then set a &#8220;wait&#8221; cursor, clear the details pane (top right of UI), then call\u00a0Get-Member on the module and store the string output to $output. We assign that string output to the .text property of the details pane and return our cursor to the default arrow. We also set several menu options to enabled to create a good UI.<\/p>\n<p><strong>Case 2<\/strong><\/p>\n<p>A module from the list can be installed by selecting the File-&gt;Install Selected Module menu option or by right-clicking the module and selecting Install.<\/p>\n<div id=\"attachment_10228\" style=\"width: 1773px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.16.04-PM.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-10228\" class=\"wp-image-10228 size-full\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.16.04-PM.png\" alt=\"Screen Shot 2015-11-03 at 2.16.04 PM\" width=\"1763\" height=\"391\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.16.04-PM.png 1763w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.16.04-PM-300x67.png 300w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.16.04-PM-1024x227.png 1024w\" sizes=\"auto, (max-width: 1763px) 100vw, 1763px\" \/><\/a><p id=\"caption-attachment-10228\" class=\"wp-caption-text\">Figure 2<\/p><\/div>\n<p>Figure 2 shows the code that is executed when that menu option is selected. First we get the module name and present a verification dialog to the user. If the user clicks OK in the dialog, then we set a wait cursor. Next we call Install-Module with the module name, PSGallery as the repository, and scope it to the current user. The output of these commands is converted to a string and output to the OutPut pane at the bottom of the application. We update our list view which will put a checkmark on the module. Finally, we set our cursor back to the default arrow.<\/p>\n<p><strong>Case 3<\/strong><\/p>\n<p>An installed module can be uninstalled by electing the File-&gt;Uninstall Selected Module menu option or right-clicking on the module and selecting Uninstall.<\/p>\n<p><a href=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.23.51-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-10230\" src=\"https:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.23.51-PM.png\" alt=\"Screen Shot 2015-11-03 at 2.23.51 PM\" width=\"928\" height=\"177\" srcset=\"https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.23.51-PM.png 928w, https:\/\/dev.sapien.com\/blog\/wp-content\/uploads\/2015\/11\/Screen-Shot-2015-11-03-at-2.23.51-PM-300x57.png 300w\" sizes=\"auto, (max-width: 928px) 100vw, 928px\" \/><\/a><\/p>\n<p>This is probably our simplest event handler. The code in figure 3 uses Try&#8230;Catch to handle any errors. In the Try section, we call Remove-Module using the text found in the first element of the list views .selectedItems array. Since there is only 1 selected item (set by an object property) we know that it will be the &#8220;0&#8221; item and the text for that selection is the module name. If this fails, then we show the error in the output pane.<\/p>\n<p><strong>Finally<\/strong><\/p>\n<p>There is a lot more going on in this application than what this post and its predecessor describe. Setting object properties, enabling and disabling menu options, etc. all work together to make a great user interface. There is plenty more that can be done with this app and we invite the community to experiment and make suggestions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Continuing on from where we left off in our last blog post entitled &#8220;PowerShellGet-GUI part 1&#8243;, let us examine some of the other features of the PowerShell Get GUI application. With our list successfully loaded with PowerShell Gallery modules, the user can take several actions: Select a module to inspect it&#8217;s properties Select a non-installed [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[22,2,946,723,25],"tags":[313,41,28,1016,1039,312],"class_list":["post-10222","post","type-post","status-publish","format-standard","hentry","category-events","category-general","category-guiprogramming","category-user-interface-design-for-administrators","category-windows-powershell","tag-forms","tag-gui","tag-powershell","tag-powershell-studio","tag-ui-design","tag-winforms"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/10222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=10222"}],"version-history":[{"count":5,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/10222\/revisions"}],"predecessor-version":[{"id":10245,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/10222\/revisions\/10245"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=10222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=10222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=10222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}