{"id":407,"date":"2014-11-04T00:01:00","date_gmt":"2014-11-04T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/11\/04\/uninstalling-the-powershell-ise-by-using-a-workflow\/"},"modified":"2014-11-04T00:01:00","modified_gmt":"2014-11-04T00:01:00","slug":"uninstalling-the-powershell-ise-by-using-a-workflow","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/uninstalling-the-powershell-ise-by-using-a-workflow\/","title":{"rendered":"Uninstalling the PowerShell ISE by Using a Workflow"},"content":{"rendered":"<p><b style=\"font-size:12px\">Summary<\/b><span style=\"font-size:12px\">: Microsoft Scripting Guy, Ed Wilson, talks about removing a Windows feature by using a Windows PowerShell workflow.<\/span>\nMicrosoft Scripting Guy, Ed Wilson, is here. This morning I am sipping a cup of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Sencha\" target=\"_blank\">Sencha green tea<\/a>. I happened to have some lying around and I decided I would go ahead and drink it this morning. I added a bit of fresh lemon and half a stick of cinnamon to the cup. It is quite good, if a bit understated. Normally, I would have green tea in the afternoon, but like I said, this morning I happened to have some lying around, so I thought, &#8220;Why not?&#8221;<i> <\/i>\nThere are, in fact, several times when I say, &#8220;Why not?&#8221;<i> <\/i>Today is one of those occasions.<\/p>\n<h2>Create a module from a Windows PowerShell workflow<\/h2>\n<p>Today I want to create a Windows PowerShell workflow that will uninstall the Windows PowerShell ISE. Then I will reboot the computer, and double check that the Windows PowerShell ISE is, in fact, uninstalled. Later, I will change it so that it will also install the Windows PowerShell ISE, so don&rsquo;t get too concerned.\nThe cool thing is that there is really no difference between creaing a workflow and storing the workflow in a script (or in a module), except that if it is in a module, I can use <b>Export-ModuleMember<\/b> to export the functions.\nWindows PowerShell considers a workflow to be a function, and I can treat the workflow in the same manner as I treat a function. This means that I will find them hanging out on the <b>Function<\/b> drive, and I can use <b>Get-Command<\/b> to find them. The advantage is that if I store my workflow in a module, I can use <b>Import-Module<\/b> to import the workflow.<\/p>\n<h2>Uninstall the ISE<\/h2>\n<p>The first thing I want to do is to create a workflow that will uninstall the Windows PowerShell ISE. To do this, I use the <b>Get-WindowsFeature<\/b> cmdlet and retrieve the <b>PowerShell-ISE<\/b> feature. I then pipe it to <b>Remove-WindowsFeature<\/b>.\nThis really the meat and potatoes of the operation. What makes it a workflow is that I use the <b>Workflow<\/b> keyword, and I define my tasks inside a <b>Parallel<\/b> script block. Here is that portion of the script:<\/p>\n<p style=\"margin-left:30px\">Workflow Uninstall-ISE<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Parallel {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-WindowsFeature PowerShell-ISE |<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove-WindowsFeature }\nWhile I am playing around, I decide to define a sequence that will restart the computer and wait for Windows PowerShell to start up on the remote computer. After that takes place, I use the <b>Get-WindowsFeature<\/b> cmdlet to ensure the Windows PowerShell ISE is uninstalled. Here is that portion of the workflow:<\/p>\n<p style=\"margin-left:30px\">Sequence {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Restart-Computer -Wait -for PowerShell<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-WindowsFeature PowerShell-ISE<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\nThe entire workflow is shown here:<\/p>\n<p style=\"margin-left:30px\">Workflow Uninstall-ISE<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Parallel {<\/p>\n<p style=\"margin-left:30px\">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Get-WindowsFeature PowerShell-ISE |<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remove-WindowsFeature }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Sequence {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Restart-Computer -Wait -for PowerShell<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-WindowsFeature PowerShell-ISE<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">}\nWhen I write code to do or undo something, at the same time, I like to write code to reverse the process. So here is that script:<\/p>\n<p style=\"margin-left:30px\">Workflow Install-ISE<\/p>\n<p style=\"margin-left:30px\">{<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Parallel {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-WindowsFeature PowerShell-ISE |<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ADD-WindowsFeature }<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp; Sequence {<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Restart-Computer -Wait -for PowerShell<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Get-WindowsFeature PowerShell-ISE<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }\n&nbsp;<\/p>\n<p style=\"margin-left:30px\">}\nCool. So how hard is it to turn this into a module? Not hard at all, I add the <b>Export-ModuleMember<\/b> command at the bottom of the script and save it as a .psm1 file. Here is the Export command:<\/p>\n<p style=\"margin-left:30px\">Export-ModuleMember -Function *\nAnd, that is it.\nI save it in a shared location because tomorrow I am going to use this module for a remote workflow to uninstall the Windows PowerShell ISE against a list of servers.\nThat is all there is to using a workflow to uninstall a feature. Workflow Week will continue tomorrow when I will talk about remotely running the workflow.\nI invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"http:\/\/blogs.technet.commailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.\n<b>Ed Wilson, Microsoft Scripting Guy<\/b><span style=\"font-size:12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about removing a Windows feature by using a Windows PowerShell workflow. Microsoft Scripting Guy, Ed Wilson, is here. This morning I am sipping a cup of Sencha green tea. I happened to have some lying around and I decided I would go ahead and drink it this morning. [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,45,382],"class_list":["post-407","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-windows-powershell","tag-workflow"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about removing a Windows feature by using a Windows PowerShell workflow. Microsoft Scripting Guy, Ed Wilson, is here. This morning I am sipping a cup of Sencha green tea. I happened to have some lying around and I decided I would go ahead and drink it this morning. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=407"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/407\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}