Issues with Registering PSRepository and Installing VMWare PowerCLI Module - powershell

My Setup: Windows 10.17134, PowerShell 5.1.17134.407
When trying to Register a new PSRepository using the Code below….
Register-PSRepository -Name "PSGallery" –SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted
….it gives me the following error:
FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
I am not able to install the VMWare PowerCLI Module with this command:
Save-module -Name vmware.powercli -path c:\temp
….it gives me this error:
FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.SavePackage

Here are the results of a days googling
I'm running
Register-PSRepository
-Name "PSGallery"
–SourceLocation "https://www.powershellgallery.com/api/v2/"
-InstallationPolicy Trusted
(multiline for clarity)
and I kept getting
Register-PSRepository : Use 'Register-PSRepository -Default' to
register the PSGallery repository. At line:1 char:1
+ Register-PSRepository -Name "PSGallery" –SourceLocation "https://www. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
+ FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
I assumed this was to do with proxy settings so I tried all of the various methods of setting the proxy in powershell to no avail.
Finally I ran
Get-PSRepository
and discovered that the repository was already registered, it was just untrusted
So I ran
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
The original reason I had for doIng this is because when I run
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
I get
Install-PackageProvider : No match was found for the specified search
criteria for the provider 'NuGet'. The package provider requires
'PackageManagement' and 'Provider' tags. Please check if the specified
package has the tags. At line:1 char:1
+ Install-PackageProvider -Name NuGet -Force -Scope CurrentUser
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (Microsoft.PowerShel\u2026tallPackageProvider:InstallPackageProvider)
[Install-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider
Unfortunately, making the repository trusted did no help with my issue
... and the original reason for doing this was so I could run
Install-Module -Name SqlServer -Force -Verbose -Scope CurrentUser
Which was failing (sorry no error message, it was so long ago)
After all my fiddling however, this statement now works without error.
Not sure if it was all the proxy config, or making NuGet trusted or both

I've been chasing this problem for days. I isolated it to Install-PackageProvider not being able to download:
Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll
In my case, my company does not allow us to download DLLs from the internet without due process. I engaged due process and got an approved copy of the DLL. Then it needs to be placed here:
$env:ProgramFiles\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Microsoft.PackageManagement.NuGetProvider.dll
Note the version becomes a folder and is stripped from the name.
Manually doing so eliminates the need to run Install-PackageProvider. Some articles state that Import-PackageProvider is necessary to get PowerShell to recognise it. But, I did not need to do the Import. Just try Install-Module -Name SqlServer -Force again.

Related

Powershell Install-PackageProvider No match was found for the specified search criteria for the provider 'NuGet

From a Windows Server 2019 server Ran as Administrator in Powershell window with the following command
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Got the following error
WARNING: MSG:UnableToDownload «https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409» «»
WARNING: Unable to download the list of available providers. Check your internet connection.
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''. Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.
At line:1 char:1 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
CategoryInfo : InvalidArgument: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-Pac
kageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForProvider,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackagePro
vider
Powershell version is 5.1.17763.2268 and is able to open public website from the machine. I tried all the suggested solutions I can find online (below) but still getting the same error. Wondering if there's anything else can be done to fix this issue?
Setting [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Setting [System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials
Get-PackageProvider | where name -eq 'nuget' | Install-PackageProvider

Can't install Exchange Online PowerShell V2 module

I'm trying to enable modern authentication for an O365 tenant, and then instructions say to import the Exchange Online Management module. I don't have that module, so those same instructions say to install it by using
Install-Module -Name ExchangeOnlineManagement -RequiredVersion 2.0.5
But then I get this error
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name
'ExchangeOnlineManagement'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772 char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], E
ception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
Just in case I did also run this to check
Get-PSRepository
And the result was
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
And that seems correct. So does anybody know why it's not working.
Thanks!
Just replying with the answer in case it helps anyone else who stumbles across this in future. It was a TLS issue, and the fix was simply:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
After that everything worked as it should.

Install Active Directory without needing RSAT

Installing Active Directory in Servers without RSAT
I am able to install Active Directory module in some servers but not
in others....
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module -AllowClobber -SkipPublisherCheck .\Microsoft.ActiveDirectory.Management.dll -ErrorAction Continue -Force
Install-Module -AllowClobber -SkipPublisherCheck .\Microsoft.ActiveDirectory.Management.resources.dll -ErrorAction Continue -Force
I keep getting this error:
PackageManagement\Install-Package : No match was found for the specified
search criteria and module name
'D:\install\ADPoSh\Microsoft.ActiveDirectory.Management.resources.dll'. Try
Get-PSRepository to see all available registered module repositories.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1772
char:21
+ ... $null = PackageManagement\Install-Package #PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPacka
ge:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.Pac
kageManagement.Cmdlets.InstallPackage
I simply copied the DLLs from the WinSXS folder on a system that has the RSAT AD Module and the C:\Windows\System32\WindowsPowerShell\v1.0\Modules\ActiveDirectory, all into the same folder.
What am I missing here?
Import-Module, not Install-Module
Wow, the answer was as simple as not using Install-Module, after the RSAT Feature install and merely running Import-Module instead! :)
So NOT THIS:
Get-WindowsFeature -Name RSAT-AD-PowerShell|Install-Windowsfeature
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-Module ActiveDirectory -Proxy proxy.verizon.com:80
But This:
Get-WindowsFeature -Name RSAT-AD-PowerShell|Install-Windowsfeature
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Import-Module ActiveDirectory -Proxy proxy.verizon.com:80
I mean, I would like to fix the repo, but, hey, AD Module works now so... yeah!

How to fix powershell after installing VS Code

I already was asking a similar question here: https://superuser.com/questions/1613630/most-of-powershell-commands-not-working?noredirect=1
Basically, I wasn't able to fix the issue so I got a replacement computer. Brand new. Started setting it up and only did the following:
Installed VS Code
Turned on Powershell extension in VS Code
It prompted something about Package Manager needing an update or it will not work properly
Asked me to install NuGet to get the Package Manager
After that PowerShell 5.1 stopped working again.
Modules not autoloading, fresh instance of powershell does this:
PS C:\WINDOWS\system32> Write-Host
Write-Host : The term 'Write-Host' 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 line:1 char:1
+ Write-Host
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Any ideas?
This fixed it for me:
(Get-Module -ListAvailable).Name | %{Import-Module -Name $_ -Force}
[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
Install-Module -Name PackageManagement -Force -RequiredVersion 1.4.6 -Scope AllUsers -AllowClobber -Verbose
Then if the last command doesn't install NuGet do this:
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

Using VSTS as PowerShell Gallery in Deployments

I have a feed for PowerShell modules in my VSTS project and I am using it as a private gallery, based on this article:
https://roadtoalm.com/2017/05/02/using-vsts-package-management-as-a-private-powershell-gallery/
Everything works great when we run this on the machine.
I need these modules as part of the release process, so the first task is to register this repo if it doesn't exist and then download and install the latest version of each module.
The relevant part of my script is:
Install-PackageProvider -Name NuGet -Confirm:$false -RequiredVersion 2.8.5.208
Get-PSRepository | Where-Object {$_.Name -eq "MyPrivateFeed" -or $_.SourceLocation -eq "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2"} | Unregister-PSRepository
Register-PSRepository -Name "MyPrivateFeed" -SourceLocation "https://myproject.pkgs.visualstudio.com/_packaging/MyPrivateFeed/nuget/v2" -InstallationPolicy Trusted
$PAT = $(System.AccessToken) | ConvertTo-SecureString -AsPlainText -Force
$VSTSCredentials = New-Object -TypeName PScredential("dummy", $PAT)
Find-Module -Name * -Repository MyPrivateFeed -Credential $VSTSCredentials | Install-Module -Credential $VSTSCredentials
The PowerShell task in the release fails with:
WARNING: Unable to find module repositories.
PackageManagement\Register-PackageSource : The property 'Values' cannot be
found on this object. Verify that the property exists.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4173
char:17
+ ... $null = PackageManagement\Register-PackageSource #PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Microsoft.Power...erPackageSource
:RegisterPackageSource) [Register-PackageSource], Exception
+ FullyQualifiedErrorId : PropertyNotFoundStrict,Microsoft.PowerShell.Pack
ageManagement.Cmdlets.RegisterPackageSource
The same exact script works on the same machine when I run it on ISE/Console (with replacing the token with the actual PAT of course)
Anyone has any idea what is going on here?
I tried adding -PackageManagementProvider NuGet to Register-PSRepository but that didn't help
I occasionally see the "Register-PackageSource : The property 'Values' cannot be found on this object. Verify that the property exists." error when attempting to run a "Register-PSRepository" command from the PowerShellGet module (or a "Register-PackageSource" command from the dependent PackageManagement module) when there are no package sources currently registered for the "PowerShellGet" package provider (not even the default "PSGallery").
This appears to happen when an empty file exists under the current user's profile at "%USERPROFILE%\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml". I'm not sure what causes that empty file to be created, but until it's deleted, not even the "Register-PSRepository -Default" command will succeed.
Deleting the file does resolve the error and allows PowerShellGet package sources to be registered again.