<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Leo’s Vision on DevOps</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/leowu/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/leowu/feed.xml</link>
    <description>Learn, Grow, Build</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:24:51 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>PowerShell Module Management</title>
      <link>https://docs.microsoft.com/archive/blogs/leowu/powershell-module-management</link>
      <pubDate>Wed, 07 Mar 2018 01:32:52 GMT</pubDate>
      <dc:creator><![CDATA[leowu70]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/leowu/?p=145</guid>
      <description><![CDATA[Working with the latest technology is great. Not only you are the top notch for the leading...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family:Times New Roman;font-size:12pt">Working with the latest technology is great. Not only you are the top notch for the leading technology but also you get job done with efficiency or impossible to do it in the past. However, there is a dark side especially working with the cloud. Things keep changing so the stuff you created today might not work next day. 
</span></p><p><span style="font-family:Times New Roman;font-size:12pt">I have built a bunch of PowerShell utilities based on AzureRM – the Azure Resource Manager module for accessing Azure resources from your local machine. I always have experience that things work perfectly but stop functioning after 2 months with various reasons – depreciate cmdlets, parameter removal, different routine introduced….etc (keep eyes on <a href="https://github.com/Azure/azure-powershell/blob/master/ChangeLog.md">azure-powershell change log</a> for every changes in the release). In order to maintain the functionality from my utilities, I end up spending quite a few time dealing with PowerShell module management. Therefore I would like to write this article to give you the fundamental how to deal with modules on your system so you can apply this technique for every PowerShell module during the troubleshoot. 
</span></p><p><span style="font-family:Times New Roman;font-size:12pt">Some basic concepts 
</span></p><ul><li>There is an environment variable called $env:PSModulePath. It is a string containing one or multiple paths where all of PowerShell modules reside. Starting with PowerShell 3.0, PowerShell implicitly import a module when one of the functions or cmdlets in the module is called by a user. (In PowerShell 2.0, you need to use the cmdlet "Import-Module" in order to use cmdlets inside that module).  The PowerShell engine will search for the module using this path and load it dynamically once it is located. 
</li><li>Starting with PowerShell version 5.0, it provides a bunch of cmdlets are introduced to communicate with PowerShell Gallery (PSGallery) site based on nuget feature. Your machine should have nuget feature or you can submit this cmdlet to install nuget: Install-PackageProvider -Name Nuget 
</li><li>The module with different versions can coexist on your machine. However, the module with the latest version will be used if you don't specify -RequiredVersion while executing the cmdlet. 
</li></ul><p><span style="font-family:Times New Roman;font-size:12pt"> To manage PowerShell module, you need to open PowerShell console with administrative permission 
</span></p><h2>List all installed versions on the machine 
</h2><p><span style="font-family:Times New Roman;font-size:12pt">This is the cmdlet that you execute to verify the completed installation of PS module on your machine. 
</span></p><div><table style="border-collapse:collapse" border="0"><colgroup><col style="width:56px" /><col style="width:56px" /><col style="width:56px" /></colgroup><tbody valign="top"><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Cmdlet</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Description</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Screenshot</span></p></td></tr><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Get-Module ` <br />-ListAvailable [<em>ModuleName</em>] </span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">This will all installed versions of PSmodule. 
</span></p><p><span style="font-family:Times New Roman;font-size:12pt"> </span> </p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><img src="https://msdnshared.blob.core.windows.net/media/2018/03/030418_2211_ManagePower1.png" alt="" /></p></td></tr></tbody></table></div><p>   
 </p><h2>Uninstall Module 
</h2><div><table style="border-collapse:collapse" border="0"><colgroup><col style="width:56px" /><col style="width:56px" /><col style="width:56px" /></colgroup><tbody valign="top"><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Cmdlet</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Description</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Screenshot</span></p></td></tr><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Uninstall-Module `<br />-Name [<em>ModuleName</em>]</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">This will uninstall the latest version of PSmodule.</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><img src="https://msdnshared.blob.core.windows.net/media/2018/03/030418_2211_ManagePower2.png" alt="" /></p></td></tr></tbody></table></div><p>   
 </p><h2>List all available versions on PSGallery 
</h2><p><span style="font-family:Times New Roman;font-size:12pt">What if you want to install a specific version of PS module and you have no idea what versions are offered on PSGallery? 
</span></p><div><table style="border-collapse:collapse" border="0"><colgroup><col style="width:56px" /><col style="width:56px" /><col style="width:56px" /></colgroup><tbody valign="top"><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Cmdlet</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Description</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Screenshot</span></p></td></tr><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Find-Module `<br />-Name [<em>ModuleName</em>] </span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">This will find PSmodule on PSGallery and returned the last version. </span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><img src="https://msdnshared.blob.core.windows.net/media/2018/03/030418_2211_ManagePower3.png" alt="" /></p></td></tr><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Find-Module `<br />-Name AzureRM `<br />-AllVersions</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">This will return all available versions of PSmodule</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><img src="https://msdnshared.blob.core.windows.net/media/2018/03/030418_2211_ManagePower4.png" alt="" /></p></td></tr></tbody></table></div><p>   
 </p><h2>Install Module 
</h2><div><table style="border-collapse:collapse" border="0"><colgroup><col style="width:56px" /><col style="width:56px" /><col style="width:56px" /></colgroup><tbody valign="top"><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Cmdlet</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Description</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  solid 0.5pt;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Screenshot</span></p></td></tr><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Install-Module `<br />-Name [<em>ModuleName</em>]</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">This will install the latest version of PSmodule.</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><img src="https://msdnshared.blob.core.windows.net/media/2018/03/030418_2211_ManagePower5.png" alt="" /></p></td></tr><tr><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  solid 0.5pt;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">Install-Module `<br />-Name [<em>ModuleName</em>] `<br />-RequiredVersion 5.2.0</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><span style="font-family:Times New Roman;font-size:12pt">This will install the specified version 5.2.0 of PSmodule</span></p></td><td vAlign="middle" style="padding-top: 4px;padding-left: 40px;padding-bottom: 4px;padding-right: 40px;border-top:  none;border-left:  none;border-bottom:  solid 0.5pt;border-right:  solid 0.5pt"><p><img src="https://msdnshared.blob.core.windows.net/media/2018/03/030418_2211_ManagePower6.png" alt="" /></p></td></tr></tbody></table></div><p> 
 </p><p><span style="font-family:Times New Roman;font-size:12pt">Here is my story from past experience dealing with AzureRM. After upgrading to version 5.4.1, I lost the capability switching to specific Azure subscription. After the lengthy process of troubleshooting, I decided to rollback to previous version in order to provide the functionality to get things going. Therefore I used cmdlets introduced above to rollback to version 5.1.1 in order to perform the function. I hope this will benefit you in the future when you deal with PowerShell module management. </span></p>]]></content:encoded>
    </item>
  </channel>
</rss>