Thursday, December 9, 2021

Install-Module Not Installing?

 

Are you trying to run Install-Module and while it looks like it's working, never actually installs the module? You might have a permissions problem.

PS C:\Users\user> install-module -Name AzureADpreview -Verbose
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='AzureADpreview'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'AzureADpreview'.
VERBOSE: Performing the operation "Install-Module" on target "Version '2.0.2.138' of module 'AzureADPreview'".
VERBOSE: The installation scope is specified to be 'AllUsers'.
VERBOSE: The specified module will be installed in 'C:\Program Files\WindowsPowerShell\Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'AzureADPreview' with version '2.0.2.138' from the repository
'https://www.powershellgallery.com/api/v2'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='AzureADPreview'' for ''.
VERBOSE: InstallPackage' - name='AzureADPreview',
version='2.0.2.138',destination='C:\Users\user\AppData\Local\Temp\924842467'
VERBOSE: DownloadPackage' - name='AzureADPreview',
version='2.0.2.138',destination='C:\Users\user\AppData\Local\Temp\924842467\AzureADPreview\AzureADPreview.nupkg',
uri='https://www.powershellgallery.com/api/v2/package/AzureADPreview/2.0.2.138'
VERBOSE: Downloading 'https://www.powershellgallery.com/api/v2/package/AzureADPreview/2.0.2.138'.
VERBOSE: Completed downloading 'https://www.powershellgallery.com/api/v2/package/AzureADPreview/2.0.2.138'.
VERBOSE: Completed downloading 'AzureADPreview'.
VERBOSE: Hash for package 'AzureADPreview' does not match hash provided from the server.
VERBOSE: InstallPackageLocal' - name='AzureADPreview',
version='2.0.2.138',destination='C:\Users\user\AppData\Local\Temp\924842467'
VERBOSE: Catalog file 'AzureADPreview.cat' is not found in the contents of the module 'AzureADPreview' being installed.
VERBOSE: Valid authenticode signature found in the file 'AzureADPreview.psd1' for the module 'AzureADPreview'.

In this case, I don't have local administrator rights on my machine but I have the ability to run Powershell as administrator and elevate as needed (through a third party app). 

I mistakenly assumed that when you run Powershell as Administrator that all the commands are run with Administrator privileges. Turns out that isn't true. And that's why the install isn't working.

Here's the workaround. Open a Run window, enter powershell.exe Install-Module -Name AzureADPreview. To run the command as Administrator, hit Ctrl+Shift+Enter. This will run the Install-Module command with the privileges of Administrator and it will actually install. 



Verify by checking the location of installed Powershell modules on your machine. You should see the installed module (AzureADPreview in my example) Unfortunately there's a few locations to check depending on your configuration.
  • C:\Program Files\WindowsPowerShell\Modules
  • C:\Windows\System32\WindowsPowerShell\v1.0\Modules
  • C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules
  • C:\Users\user\Documents\WindowsPowerShell


I'm posting this because I spent some time banging my head against the wall without finding answers on Google. Hopefully this helps someone else.