{"id":11130,"date":"2016-02-17T06:00:41","date_gmt":"2016-02-17T14:00:41","guid":{"rendered":"https:\/\/www.sapien.com\/blog\/?p=11130"},"modified":"2016-02-10T08:23:26","modified_gmt":"2016-02-10T16:23:26","slug":"update-module-5-0-adds-not-updates","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2016\/02\/17\/update-module-5-0-adds-not-updates\/","title":{"rendered":"Update-Module 5.0 adds, not updates"},"content":{"rendered":"<hr \/>\n<p><em>Applies to:<\/em><\/p>\n<p>&#8212; Windows PowerShell 5.0.10586.63<br \/>\n&#8212; PowerShellGet 1.0.0.1<\/p>\n<hr \/>\n<p>I&#8217;m a huge fan of sharing Windows PowerShell modules and making them easy to find (<a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/dn807167.aspx\" target=\"_blank\">Find-Module<\/a>), view (<a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/mt653992.aspx\" target=\"_blank\">Save-Module<\/a>), and install (<a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/dn807162.aspx\" target=\"_blank\">Install-Module<\/a>). So, I truly love the new\u00a0<a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/dn807169.aspx\" target=\"_blank\">PowerShellGet module<\/a>.<\/p>\n<p>However, you really need to understand how it works before you use it. Otherwise, you might end up with commands and modules that don&#8217;t work correctly (or at all)\u00a0or don&#8217;t do what you expect.\u00a0Or, you\u00a0might download modules with commands that shadow or hide commands that your scripts run.<\/p>\n<p><strong>Update-Module<\/strong> is one of the\u00a0really useful cmdlets in PowerShellGet, but if you don&#8217;t know how it works, it might surprise you. In Windows PowerShell 5.0, Update-Module doesn&#8217;t update\u00a0a\u00a0module. It adds one.<\/p>\n<p>And, this is important to understand, because when you have side-by-side versions of the same module, you might mistakenly import the wrong version of a module or run the wrong version of a command.<\/p>\n<p>I once made the mistake of piping <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/mt653990.aspx\" target=\"_blank\">Get-InstalledModule<\/a> (all of them) to <strong>Update-Module<\/strong>. It took a long time to run and it installed additional versions of many of my modules in my poor, bloated Modules directory.<\/p>\n<p>Here&#8217;s how\u00a0<strong>Update-Module<\/strong> works:<\/p>\n<ul>\n<li>When\u00a0you use <strong>Update-Module<\/strong> with no version parameters, it checks to see if the <strong>newest<\/strong> version of the module\u00a0is\u00a0newer than the newest version you have. If it is, it installs the newest version <strong>beside<\/strong> the current version in the same directory. Otherwise, it does nothing.<\/li>\n<\/ul>\n<pre class=\"output\">PS C:\\&gt; Get-Module -List PowerForensics\r\n\r\nDirectory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\nModuleType Version\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0ExportedCommands\r\n---------- -------\u00a0\u00a0\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0----------------\r\nBinary\u00a0\u00a0\u00a0\u00a0 1.0.2\u00a0\u00a0\u00a0\u00a0\u00a0 PowerForensics\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ConvertFrom-BinaryData, ConvertTo-ForensicTimeline\r\n\r\nPS C:\\&gt; Update-Module PowerForensics\r\nPS C:\\&gt; Get-Module -List PowerForensics\r\nDirectory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\nModuleType Version\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ExportedCommands\r\n---------- -------\u00a0\u00a0\u00a0 ----\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0----------------\r\nBinary\u00a0\u00a0\u00a0\u00a0 1.1.1\u00a0\u00a0\u00a0\u00a0\u00a0 PowerForensics\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ConvertFrom-BinaryData, ConvertTo-ForensicTimeline\r\nBinary\u00a0\u00a0\u00a0\u00a0 1.0.2\u00a0\u00a0\u00a0\u00a0\u00a0 PowerForensics\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{ConvertFrom-BinaryData, ConvertTo-ForensicTimeline\r\n<\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li>When\u00a0you use <strong>Update-Module<\/strong> with\u00a0the <strong>RequiredVersion<\/strong> parameter, it checks to see\u00a0if\u00a0the <strong>specified<\/strong> version of the module is\u00a0already installed. If it is not, it installs the\u00a0specified version <strong>beside<\/strong> the current version in the same directory. Otherwise, it does nothing.In this example, I use -RequiredVersion to install an earlier version of the module.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<pre class=\"output\">PS C:\\&gt; Get-Module -List xJea\r\n\r\n    Directory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\n\r\nModuleType Version    Name        ExportedCommands\r\n---------- -------    ----        ----------------\r\nManifest   0.2.10     xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\n\r\nPS C:\\&gt; Update-Module xJea -RequiredVersion 0.2.9\r\nPS C:\\&gt; Get-Module -List xJea\r\n\r\n    Directory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\n\r\nModuleType Version    Name        ExportedCommands\r\n---------- -------    ----        ----------------\r\nManifest   0.2.10     xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\nManifest   0.2.9      xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\n<\/pre>\n<ul>\n<li>When\u00a0you use <strong>Update-Module<\/strong> with\u00a0the <strong>MaximumVersion<\/strong> parameter, it\u00a0determines whether\u00a0it has a version equal to or greater than the specified version. If it does and\u00a0if (IFF) the selected version is <strong>newer<\/strong> than the newest\u00a0version of the module\u00a0that is\u00a0installed, it installs the\u00a0selected version <strong>beside<\/strong> the current version in the same directory. Otherwise, it does nothing.<\/li>\n<\/ul>\n<pre class=\"output\">PS C:\\&gt; Get-Module -List xJea\r\n\r\n    Directory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\n\r\nModuleType Version    Name        ExportedCommands\r\n---------- -------    ----        ----------------\r\nManifest   0.2.10     xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\nManifest   0.2.9      xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\n\r\nPS C:\\&gt; Find-Module -Name xJea -RequiredVersion 0.2.8\r\n\r\nVersion    Name      Type       Repository           Description\r\n-------    ----      ----       ----------           -----------\r\n0.2.8      xJea      Module     PSGallery            Module with DSC Resources f\r\n\r\n\r\nPS C:\\&gt; Update-Module -Name xJea -MaximumVersion 0.2.8\r\nPS C:\\&gt; Get-Module -List xJea\r\n\r\n    Directory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\n\r\nModuleType Version    Name        ExportedCommands\r\n---------- -------    ----        ----------------\r\nManifest   0.2.10     xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\nManifest   0.2.9      xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}...\r\n\r\nPS C:\\&gt; Update-Module -Name xJea -MaximumVersion 0.2.11\r\nPS C:\\&gt; Get-Module -List -Name xJea\r\n\r\n    Directory: C:\\Users\\JuneB\\Documents\\WindowsPowerShell\\Modules\r\n\r\nModuleType Version    Name        ExportedCommands\r\n---------- -------    ----        ----------------\r\nManifest   0.2.11     xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}\r\nManifest   0.2.10     xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}\r\nManifest   0.2.9      xJea        {Show-JeaPresentation, show-JeaWhitePaper, Show-JeaExamples}\r\n<\/pre>\n<ul>\n<li>With the <strong>Force<\/strong> parameter, Update-Module skips all checks for versions currently installed on the computer. As a result, with -Force, Update-Module actually updates, that is, replaces, the specified version of the module if it&#8217;s already installed on the computer. If the requested version is not installed, Update-Module installs it, even if it&#8217;s older than an currently installed version.<\/li>\n<\/ul>\n<pre class=\"output\">PS C:\\&gt; Update-Module -Name xJea -RequiredVersion 0.2.10 -Verbose\r\n<span style=\"color: yellow;\">VERBOSE: Checking for updates for module 'xJea'.\r\nVERBOSE: Repository details, Name = 'PSGallery', Location = 'https:\/\/www.powershellgallery.co\r\nIsRegistered = 'True'.\r\nVERBOSE: Using the provider 'PowerShellGet' for searching packages.\r\nVERBOSE: Using the specified source names : 'PSGallery'.\r\nVERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.\r\nVERBOSE: The specified Location is 'https:\/\/www.powershellgallery.com\/api\/v2\/' and PackageMan\r\nVERBOSE: Searching repository 'https:\/\/www.powershellgallery.com\/api\/v2\/FindPackagesById()?id\r\nVERBOSE: Total package yield:'1' for the specified package 'xJea'.\r\nVERBOSE: Skipping installed module xJea 0.2.10.<\/span>\r\n\r\nPS C:\\&gt; Update-Module -Name xJea -RequiredVersion 0.2.10 -Verbose -Force\r\n<span style=\"color: yellow;\">VERBOSE: Checking for updates for module 'xJea'.\r\nVERBOSE: Repository details, Name = 'PSGallery', Location = 'https:\/\/www.powershellgallery.co\r\nIsRegistered = 'True'.\r\nVERBOSE: Using the provider 'PowerShellGet' for searching packages.\r\nVERBOSE: Using the specified source names : 'PSGallery'.\r\nVERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.\r\nVERBOSE: The specified Location is 'https:\/\/www.powershellgallery.com\/api\/v2\/' and PackageMan\r\nVERBOSE: Searching repository 'https:\/\/www.powershellgallery.com\/api\/v2\/FindPackagesById()?id\r\nVERBOSE: Total package yield:'1' for the specified package 'xJea'.\r\nVERBOSE: Performing the operation \"Update-Module\" on target \"Version '0.2.10' of module 'xJea\r\nVERBOSE: The installation scope is specified to be 'CurrentUser'.\r\nVERBOSE: The specified module will be installed in 'C:\\Users\\JuneBlender\\Documents\\WindowsPow\r\nVERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.\r\nVERBOSE: Downloading module 'xJea' with version '0.2.10' from the repository 'https:\/\/www.pow\r\nVERBOSE: Searching repository 'https:\/\/www.powershellgallery.com\/api\/v2\/FindPackagesById()?id\r\nVERBOSE: InstallPackage' - name='xJea', version='0.2.10',destination='C:\\Users\\JuneBlender\\Ap\r\nVERBOSE: DownloadPackage' - name='xJea',\r\nversion='0.2.10',destination='C:\\Users\\JuneBlender\\AppData\\Local\\Temp\\1556275497\\xJea\\xJea.nu\r\nuri='https:\/\/www.powershellgallery.com\/api\/v2\/package\/xJea\/0.2.10'\r\nVERBOSE: Downloading 'https:\/\/www.powershellgallery.com\/api\/v2\/package\/xJea\/0.2.10'.\r\nVERBOSE: Completed downloading 'https:\/\/www.powershellgallery.com\/api\/v2\/package\/xJea\/0.2.10'\r\nVERBOSE: Completed downloading 'xJea'.\r\nVERBOSE: InstallPackageLocal' - name='xJea', version='0.2.10',destination='C:\\Users\\JuneBlend\r\nVERBOSE: Module 'xJea' was installed successfully.<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>If you&#8217;re worried about side-by-side versions, you can use the <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/mt653990.aspx\" target=\"_blank\">Get-InstalledModule<\/a> and <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/mt653996.aspx\">Uninstall-Module<\/a> cmdlets to uninstall\u00a0all older versions.<\/p>\n<pre class=\"output\">PS C:\\&gt; Get-InstalledModule -Name xJea -AllVersions\r\n\r\nVersion    Name         Type       Repository           Description\r\n-------    ----         ----       ----------           -----------\r\n0.2.10     xJea         Module     PSGallery            Module with DSC\r\n0.2.11     xJea         Module     PSGallery            Module with DSC\r\n0.2.8      xJea         Module     PSGallery            Module with DSC\r\n0.2.9      xJea         Module     PSGallery            Module with DSC\r\n\r\nPS C:\\&gt; Get-InstalledModule -Name xJea -AllVersions | \r\n           Sort Version -Descending | \r\n           Select-Object -Skip 1 | \r\n           Uninstall-Module\r\n\r\nPS C:\\&gt; Get-InstalledModule -Name xJea -AllVersions\r\n\r\nVersion    Name       Type       Repository           Description\r\n-------    ----       ----       ----------           -----------\r\n0.2.11     xJea       Module     PSGallery            Module with DSC Resources for Just Enough Ad\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>So, how does <strong>Update-Module<\/strong> differ from the <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/dn807162.aspx\" target=\"_blank\">Install-Module<\/a> cmdlet?<\/p>\n<ul>\n<li>\u00a0It install only newer versions of the module (without <strong>-Force<\/strong>).<\/li>\n<li>\u00a0It always installs its versions of the module in the same directory. It doesn&#8217;t not have a <strong>Scope<\/strong> or <strong>Path<\/strong>\u00a0parameter.<\/li>\n<li>\u00a0It does not have\u00a0a <strong>MinimumVersion<\/strong> parameter.<\/li>\n<li>\u00a0None of the parameters have a <strong>Version<\/strong> alias.\u00a0In the\u00a0<strong>Import-Module<\/strong>, <strong>Find-Module<\/strong>, <strong>Save-Module<\/strong>, and <strong>Install-Module<\/strong> cmdlets, <strong>-Version<\/strong> is an alias for the <strong>MinimumVersion<\/strong> parameter.<\/li>\n<\/ul>\n<p>And, just to make things interesting, the new <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/mt653997.aspx\" target=\"_blank\">Update-Script<\/a> cmdlet actually updates the specified script. It does not install a newer version of the script in the same directory or in a versioned subdirectory.<\/p>\n<p>In summary, Update-Module is great, but you need to understand how it works.<\/p>\n<p><em>June Blender is a technology evangelist at SAPIEN Technologies, Inc. and a Windows PowerShell MVP. You can reach her at <\/em><a href=\"mailto:juneb@sapien.com\"><em>juneb@sapien.com<\/em><\/a><em>\u00a0and follow her on Twitter at <\/em><a href=\"https:\/\/twitter.com\/juneb_get_help\"><em>@juneb_get_help<\/em><\/a><em>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Applies to: &#8212; Windows PowerShell 5.0.10586.63 &#8212; PowerShellGet 1.0.0.1 I&#8217;m a huge fan of sharing Windows PowerShell modules and making them easy to find (Find-Module), view (Save-Module), and install (Install-Module). So, I truly love the new\u00a0PowerShellGet module. However, you really need to understand how it works before you use it. Otherwise, you might end up [&hellip;]<\/p>\n","protected":false},"author":31,"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":[932,1034,2,283,941,703,25],"tags":[934,551,28,961,1016,1053,57],"class_list":["post-11130","post","type-post","status-publish","format-standard","hentry","category-beginners","category-best-practices","category-general","category-howto","category-powershell-5-0","category-powershell-studio","category-windows-powershell","tag-juneb","tag-modules","tag-powershell","tag-powershell-5-0","tag-powershell-studio","tag-powershellget","tag-scripting"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/11130","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\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=11130"}],"version-history":[{"count":12,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/11130\/revisions"}],"predecessor-version":[{"id":11142,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/11130\/revisions\/11142"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=11130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=11130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=11130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}