Powershell – Install PowerShellGet module

powershell

I am working on Windows 2012 R2 and it was running PowerShell version 4.0. I have upgraded to version 5.0.

It seems like that when I do basic commands I get errors, for example,

PS C:\Windows\system32> Install-Module –Name PowerShellGet –Force –Verbose

Install-Module : The 'Install-Module' command was found in the module
'PowerShellGet', but the module could not be loaded. For more
information, run 'Import-Module PowerShellGet'. At line:1 char:1
+ Install-Module –Name PowerShellGet –Force –Verbose
+ ~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Another example:

PS C:\Windows\system32> import-module PowerShellGet

Get-Variable : The term 'Get-Variable' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path
is correct and try again. At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.1.3.2\PSModule.psm1:18
char:28
+ $script:IsWindows = (-not (Get-Variable -Name IsWindows -ErrorAction …
+ ~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-Variable:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

I am basically following the installation method for PowerShellGet found here: https://docs.microsoft.com/en-us/powershell/gallery/psget/get_psget_module

I am stuck at the "Install-Module" command in this guide.

Best Answer

Execute the command on your powershell: 'Set-ExecutionPolicy Unrestricted' before executing install-module. (The restricted mode helps you protect from the the unauthorized scripts)

Related Topic