Using PowerShell (version 5.1.17134.228), found some unexpected differences between Get-Module and Get-InstalledModule, in that some modules that I'd expect to be returned by Get-InstalledModule are not.
As an example:
Get-Module -ListAvailable -Name 'Hyper-V'
Get-InstalledModule -Name 'Hyper-V'
Output:
PS C:\> Get-Module -ListAvailable -Name 'Hyper-V'
Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 2.0.0.0 Hyper-V {Add-VMAssignableDevice, Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMGpuPartitionAdapter...}
Binary 1.1 Hyper-V {Add-VMDvdDrive, Add-VMFibreChannelHba, Add-VMHardDiskDrive, Add-VMMigrationNetwork...}
PS C:\> Get-InstalledModule -Name 'Hyper-V'
PackageManagement\Get-Package : No match was found for the specified search
criteria and module names 'Hyper-V'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.6.5\PSModule.psm1:9125 char:9
+ PackageManagement\Get-Package #PSBoundParameters | Microsoft. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
As you can see, the Get-Module command is returning a local path of the Hyper-V modules, so it's definitely installed locally, but Get-InstalledModule cannot find the module.
Is this a bug or have I misunderstood what Get-InstalledModule is meant to do?
Related
My Powershell v5.1 won't install almost any module automatically using install-module whereas manually installation does work.
First, when I run install-module, it would download the module then throw an error, say the pscx module:
PackageManagement\Install-Package : Package 'Pscx' failed to be installed because: Specified cast is not valid.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:9307 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (Pscx:String) [Install-Package], Exception
+ FullyQualifiedErrorId : Package '{0}' failed to be installed because: {1},Microsoft.PowerShell.PackageManag
ement.Cmdlets.InstallPackage
What I can do now is to manually download the module and use import-module myself. The error occurs almost every time when I'm trying to install any module through this cmdlet. How can I address this problem?
For troubleshooting, Get-PSRepository gives me this:
PS C:\> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Trusted https://www.powershellgallery.com/api/v2
GalleryRolling Trusted https://www.poshtestgallery.com/api/v2/
EDIT:
Got the same error when trying to use Save-Module:
PS C:\> Find-Module -Name 'pscx' | Save-Module -Path "G:\Temp\System Documents\WindowsPowerShell\Modules"
WARNING: Package 'Pscx' failed to be installed because: Specified cast is not valid.
WARNING: Package 'Pscx' failed to install.
PackageManagement\Save-Package : Unable to save the module 'Pscx'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:11331 char:25
+ ... $null = PackageManagement\Save-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power...ets.SavePackage:SavePackage) [Save-Packag
e], Exception
+ FullyQualifiedErrorId : ProviderFailToDownloadFile,Microsoft.PowerShell.PackageManagement.Cmdlets.Save
Package
It downloaded the package then displays the WARNING.
When using the Find-Module alone, the result is:
PS C:\> Find-Module -Name 'pscx'
Version Name Repository Description
------- ---- ---------- -----------
3.3.2 Pscx PSGallery PowerShell Community Extensi...
EDIT 2:
Oh I forgot to say that there are no files created in the specific download folder after the download process bar disappeared. Does that mean the download has failed?
EDIT 3: #Sage Pourpre
Debugging log
I Always run PS as administrator.
-Scope CurrentUser throws the same error.
Both PS C:\> Uninstall-Module -Name "PowerShellGet" and PS C:\> Uninstall-Script -Name "PowerShellGet" -RequiredVersion 2.0.3 produce the same result.
PackageManagement\Uninstall-Package : No match was found for the specified search criteria and script names
'PowerShellGet'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:12343 char:21
... $null = PackageManagement\Uninstall-Package #PSBoundParameters
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstal
l-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
Then I tried to list available modules:
PS C:\> Get-Module -ListAvailable
Directory: G:\Temp\System Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 2.7.1.7 ISESteroids {Get-PSSharperData, Add-SteroidsContextMenuComma...
Script 1.2 Use-RawPipeline {Invoke-NativeCommand, Receive-RawPipeline, Get-...
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.0.1 Microsoft.PowerShell.Operation.V... {Get-OperationValidation, Invoke-OperationValida...
Script 1.2.4 PackageManagement {Find-Package, Get-Package, Get-PackageProvider,...
Script 4.5.0 Pester {Describe, Context, It, Should...}
Script 2.0.4 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Fi...
Script 2.0.3 PowerShellGet {Find-Command, Find-DSCResource, Find-Module, Fi...
Script 1.2 PSReadline {Get-PSReadlineKeyHandler, Set-PSReadlineKeyHand...
Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 1.0.0.0 AppBackgroundTask {Disable-AppBackgroundTaskDiagnosticLog, Enable-...
Manifest 2.0.0.0 AppLocker {Get-AppLockerFileInformation, Get-AppLockerPoli...
Manifest 1.0.0.0 AppvClient {Add-AppvClientConnectionGroup, Add-AppvClientPa...
Manifest 2.0.0.0 Appx {Add-AppxPackage, Get-AppxPackage, Get-AppxPacka...
Script 1.0.0.0 AssignedAccess {Clear-AssignedAccess, Get-AssignedAccess, Set-A...
Manifest 1.0.0.0 BitLocker {Unlock-BitLocker, Suspend-BitLocker, Resume-Bit...
etc...
And Get-InstalledModule
PS C:\> Get-InstalledModule -Name "PowerShellGet" -RequiredVersion 2.0.3
PackageManagement\Get-Package : No match was found for the specified search criteria and module names
'PowerShellGet'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.4\PSModule.psm1:9050 char:9
+ PackageManagement\Get-Package #PSBoundParameters | Microsoft. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package],
Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
Finally solved by:
[Net.ServicePointManager]::SecurityProtocol = "tls12"
The solution is from the following blog posted by vanBrenk:
Trying to install a PowerShell module behind a proxy? Chances are you're getting this error: "Unable to resolve package source 'https://www.powershellgallery.com/api/v2/'". Turns out it isn't allowed through your proxy server [...] Now every command you run is sent and allowed through the proxy.
If you are just using the default repo, there is not reason to specify it.
Try it this way...
Find-Module -Name 'pscx' |
Save-Module -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
Install-Module -Name 'pscx'
You can have multiple version of PowerShell on the same site, it should not impact installing modules, generally.
I'd like to use functionality from the latest Azure Powershell library but I'm struggling to install it. This is on an AWS x64 Windows 2012 R2 Standard server.
I get the following error
PS C:\Users\Administrator> Install-Module -Name AzureAD
WARNING: Cannot find an overload for "SoftwareIdentity" and the argument count: "17".
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'AzureAD'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\PSModule.psm1:1809 char:21
+ $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
This is with PSVersion = 4.0
Get-Module shows: 3.1.0.0 Microsoft.PowerShell.Management, 3.1.0.0 Microsoft.PowerShell.Utility Script, 1.1.1.0 PackageManagement Script, 1.1.2.0 PowerShellGet
Get-PSRepository shows PSGallery Untrusted https://www.powershellgallery.com/api/v2/
Do you have any pointers to help troubleshoot / fix please?
Thanks
Ok so I installed Win8.1AndW2K12R2-KB3134758-x64.msu from https://www.microsoft.com/en-us/download/details.aspx?id=50395
Now Get-Module returns nothing and the first time I tried Install-Module -Name AzureAD it moaned about the -Name parameter. Second time (which I'm assuming means I'm imagining the first time) it worked. Now to see if I can add a user to an Azure AD group using the latest OpenICF connector scripts.
I apologize if this is a NOOB question but I wrote a PowerShell script on my windows 10 box and I am trying to run the script on a 2008 box. On the new install of the 2008 box I had to add the windows powershell feature. My end goal is to install the Web Server (IIS) Administration Cmdlets
PS C:\Users\Administrator> Get-Module -ListAvailable | Import-Module
PS C:\Users\Administrator> Get-Module -ListAvailable
ModuleType Name ExportedCommands
---------- ---- ----------------
Manifest BitsTransfer {}
Manifest PSDiagnostics {Enable-PSTrace, Enable-WSManTrace, Start-Trace, Disable-PSWSManCombined...
PS C:\Users\Administrator>
PS C:\Users\Administrator> add-pssnapin WebAdministration
Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.
At line:1 char:13
+ add-pssnapin <<<< WebAdministration
+ CategoryInfo : InvalidArgument: (WebAdministration:String) [Add-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand
PS C:\Users\Administrator>
PS C:\Users\Administrator> Import-Module WebAdministration
Import-Module : The specified module 'WebAdministration' was not loaded because no valid module file was found in any module directory.
At line:1 char:14
+ Import-Module <<<< WebAdministration
+ CategoryInfo : ResourceUnavailable: (WebAdministration:String) [Import-Module], FileNotFoundException
+ FullyQualifiedErrorId :Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand
Any ideas?
You need to install the IIS managment tools before the WebAdministration-module is available. Try (tested on Win10):
Enable-WindowsOptionalFeature -Online -FeatureName "IIS-WebServerManagementTools" -All
Windows Server 2008 doesn't come with a PowerShell module for managing IIS. That feature was added with Windows Server 2008 R2. You need to download and install it first. See here for further information. See also this related question.
I have a computer behind a proxy and trying to get the Nuget package provider installed. I ran Install-PackageProvider -Name Nuget on a different PC on a different network and copied Nuget folder to $env:ProgramFiles\PackageManagement\ProviderAssemblies.
If I run Get-PackageProvider -ListAvailable it shows Nuget available.
PS C:\Windows\system32> Get-PackageProvider -ListAvailable
Name Version DynamicOptions
---- ------- --------------
msi 3.0.0.0 AdditionalArguments
msu 3.0.0.0
nuget 2.8.5.204
PowerShellGet 1.0.0.1 PackageManagementProvider, Type, S...
Programs 3.0.0.0 IncludeWindowsInstaller, IncludeSy...
However when I try to run Import-PackageProvider -Name Nuget I get the following error:
PS C:\Windows\system32> Import-PackageProvider -Name Nuget
Import-PackageProvider : No match was found for the specified search criteria and provider name 'Nuget'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.At line:1 char:1
+ Import-PackageProvider -Name Nuget
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Nuget:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider
Any suggestions? Thank you!
I was able to work around the proxy by using the following:
$wc = New-Object System.Net.WebClient
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.Proxy.Address = "http://proxyurl"
Once I did this I was able to use Install-PackageProvider Nuget to install the proivder.
I'm following Get Started with the PowerShell Gallery which states that the PowerShellGet module exists in Windows 10 (which I am using - build 14721). To confirm, I am running PowerShell v5:
>$PSVersionTable
Name Value
---- -----
PSVersion 5.0.14271.1000
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14271.1000
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Get Started with the PowerShell Gallery states:
PowerShellGet also requires the NuGet provider to work with the PowerShell Gallery. You will be prompted to install the NuGet provider automatically upon first use of PowerShellGet if the NuGet provider is not in one of the following locations:
•$env:ProgramFiles\PackageManagement\ProviderAssemblies
•$env:LOCALAPPDATA\PackageManagement\ProviderAssemblies
I don't have anything in those locations:
>ls $env:LOCALAPPDATA\PackageManagement\ProviderAssemblies
>ls $env:ProgramFiles\PackageManagement\ProviderAssemblies
ls : Cannot find path 'C:\Program Files\PackageManagement\ProviderAssemblies' because it does not exist.
At line:1 char:1
+ ls $env:ProgramFiles\PackageManagement\ProviderAssemblies
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Program File...viderAssemblies:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Get Started with the PowerShell Gallery then states:
Or, you can run Install-PackageProvider -Name NuGet -Force to automate the download and installation of the NuGet provider.
If I try that:
>Install-PackageProvider -Name NuGet -Force
Install-PackageProvider : The term 'Install-PackageProvider' is not recognized as the name of a cmdlet, function, script file, or operable program.
correct and try again.
At line:1 char:1
+ Install-PackageProvider -Name NuGet -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Install-PackageProvider:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
I'm very confused. I have PowerShell v5 but it seems I don't have everything that's supposed to be there, namely PowerShellGet.
Can someone explain why?
When I did Get-Module -ListAvailable -Name PackageManagement, as Adam Bertram suggested, I found that there was a different version in my home folder, cruft from a previous install of Windows that got copied across to a new machine:
> Get-Module -ListAvailable -Name PackageManagement
Directory: C:\Users\<myusername>\Documents\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Script 1.4.7 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 1.0.0.1 PackageManagement {Find-Package, Get-Package, Get-PackageProvider, Get-Packa..
Deleting this version, or before that just forcing the system version to be used with Import-Module PackageManagement -RequiredVersion 1.0.0.1, allowed me to get the NuGet provider installed.
"Install-PackageProvider" was not introduced until PowerShell 5.1
This error means that PowerShell can't find the module that Install-PackageProvider is a part of. Install-PackageProvider is a member of the PackageManagement module. To verify this, run Get-Module
Get-Module -ListAvailable -Name PackageManagement
If this errors out, you'll need to ensure you have the PackageManagement folder a folder inside of your $env:PSModulePath. Here's a quick way to look through each of the folders for the PackageManagement folder.
$env:psmodulepath.Split(';') | foreach {gci $_ -filter '*packagemanagement*'}
If nothing comes back, you don't even have the PackageManagement module folder anywhere where it can be auto-imported by PowerShell.
If that's the case, I'd recommend to reinstall PowerShell v5 RTM.
I had to open up the folder
Directory: C:\Users<myusername>\Documents\WindowsPowerShell\Modules
and rename/delete the PackageManagement folder
Then everything started working more better.
On my Win2019, Get-PackageProvider (with capital letters) didn't work but get-packageprovider did.
This Powershell that should be "the" solution always surprises me :-/