Powershell error saying the gallery is unavailable try again later - powershell

I am running into this issue where iam unable to install any modules. even when i try to register i get this error. any ideas on resolving this appreciate it.
PS C:\Users\abc> Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4095 char:9
+ Get-PSGalleryApiAvailability -Repository $Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
+ FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
At line:1 char:1
+ Register-PSRepository -Name PSGallery -SourceLocation https://www.pow ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
+ FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
PS C:\Users\abc> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.17134.858
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.858
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
-- adding some more commands
Find-PackageProvider -Name nuget
WARNING: Unable to download from URI 'https://go.microsoft.com/fwlink/?LinkID=627338&clcid=0x409' to ''.
WARNING: Unable to download the list of available providers. Check your internet connection.
Find-PackageProvider : No match was found for the specified search criteria and package name 'nuget'. Try
Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Find-PackageProvider -Name nuget
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...PackageProvider:FindPackageProvider) [Find-PackagePro
vider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvid
er
Register seems to complete without any errors, but nothing gets added
PS C:\Users\abc> Register-PSRepository -Default
PS C:\Users\abc> Get-PSRepository
WARNING: Unable to find module repositories.
PS C:\Users\abc>
PS C:\Users\abc> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
PS C:\Users\abc> Register-PSRepository -Name PSGallery -SourceLocation https://www.powershellgallery.com/api/v2
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4095 char:9
+ Get-PSGalleryApiAvailability -Repository $Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
+ FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
Register-PSRepository : Use 'Register-PSRepository -Default' to register the PSGallery repository.
At line:1 char:1
+ Register-PSRepository -Name PSGallery -SourceLocation https://www.pow ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (PSGallery:String) [Register-PSRepository], ArgumentException
+ FullyQualifiedErrorId : UseDefaultParameterSetOnRegisterPSRepository,Register-PSRepository
PS C:\Users\abc> Get-PSRepository
WARNING: Unable to find module repositories.

Try forcing tls 1.2. This solves most powershell gallery issues
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Not really a solution, but rather an FYI piece.
This also seems to happen regularly every three months now when TLS cert in https://www.powershellgallery.com/api/v2 expires. For some reason, Microsoft are struggling to get the cert renewal to work properly.
When this happens, none of the above mentioned solutions will work.
In fact, this is happening right now, as I type this...
https://github.com/PowerShell/PowerShellGallery/issues/166
To see if the issue is caused by the expired (or otherwise invalid) cert, just open this URL https://www.powershellgallery.com/api/v2 in a browser and see if the browser complains about the certificate.
If you need to make it work just this one time, you can try tricking Powershell into ignoring invalid certificates like so:
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true};
...but be warned:
a) this is a bad practice and you shouldn't really have it as a permanent solution because this will expose you to man-in-the-middle attack; and
b) this may not help you because Microsoft guys usually disable PSGallery API when this situation happens. To check if the API is disabled right now, run:
# Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Get-PSGalleryApiAvailability : PowerShell Gallery is currently unavailable. Please try again later.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4302 char:9
+ Get-PSGalleryApiAvailability -Repository $Name
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-PSGalleryApiAvailability], InvalidOperationException
+ FullyQualifiedErrorId : PowerShellGalleryUnavailable,Get-PSGalleryApiAvailability
Update:
Also look here for any current ongoing issues with PSGallery:
https://github.com/PowerShell/PowerShellGallery/blob/master/psgallery_status.md

Actually forcing tls12 is not enough to solve, but, reading carefully to the error message said: Use 'Register-PSRepository -Default'
So I tried: register-psrepository -Default
PS C:\Windows\system32> register-psrepository -Default
PS C:\Windows\system32> get-psrepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2
And it solve the problem.

Related

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.

Issues with Registering PSRepository and Installing VMWare PowerCLI Module

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.

How to set PITR for all databases in a Azure Sql Database Elastic Pool?

I think I'm running into version issues because the cmdlet I want seems to only be available in AzureRM.Sql module version 4.7.0-preview.
I want to set the PITR retention policy for many databases in an elastic pool to 35 days. By default my vCore pool has a retention policy of 7 days which is not enough. I have hundreds of databases so need to set them all with PowerShell.
If I get the list of databases to update with Get-AzureRmSqlElasticPoolDatabase and then try to run Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy I get this error when running the latter:
import-module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureSqlDatabaseCopyModel": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureReplicationLinkModel": The member DefaultDisplayPropertySet is already present.
At line:1 char:1
+ import-module azurerm.sql
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
Things I've tried
I've tried removing the module and re-importing it. Same error.
I've tried importing the required version of the module and getting the database list with the first command but I then get this error:
Get-AzureRmSqlElasticPoolDatabase : The 'Get-AzureRmSqlElasticPoolDatabase' command was found in the module 'AzureRM.Sql', but the module could not be loaded. For more information, run 'Import-Module AzureRM.Sql'.
At line:1 char:8
+ $dbs = Get-AzureRmSqlElasticPoolDatabase -ElasticPoolName $settings.E ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzureRmSqlElasticPoolDatabase:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CouldNotAutoloadMatchingModule
If I import the AzureRm module with import-module azurerm.sql I get this error:
import-module : The following error occurred while loading the extended type data file: Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureSqlDatabaseCopyModel": The member DefaultDisplayPropertySet is already present.
Error in TypeData "Microsoft.Azure.Commands.Sql.Replication.Model.AzureReplicationLinkModel": The member DefaultDisplayPropertySet is already present.
At line:1 char:1
+ import-module azurerm.sql
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Import-Module], RuntimeException
+ FullyQualifiedErrorId : FormatXmlUpdateException,Microsoft.PowerShell.Commands.ImportModuleCommand
Modules
Get-Module AzureRm -ListAvailable | select Name, Version:
Name Version
---- -------
AzureRM 6.10.0
Get-Module AzureRm.Sql -ListAvailable | select Name, Version:
Name Version
---- -------
AzureRM.Sql 4.11.5
AzureRM.Sql 4.7.0
AzureRM.Sql 4.4.0
$PSVersionTable:
Name Value
---- -----
PSVersion 5.1.17134.228
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.228
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Any ideas on how to get this working?
You could try to install 4.11.4-preview version of AzureRM.Sql module, refer to this link, use Install-Module -Name AzureRM.Sql -RequiredVersion 4.11.4-preview -AllowPrerelease in the powershell administrator environment.
After installing it, no need to import module, you could excute the command straightly. If you want to check the module if installs successfully, navigate to C:\Program Files\WindowsPowerShell\Modules\AzureRM.Sql, you will find a 4.11.4 folder.
Then try the sample command to set PITR for all databases in a Elastic Pool , it works fine on my side.(You could execute Get-Help Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy to get the usage of the command)
$dbs = Get-AzureRmSqlElasticPoolDatabase -ResourceGroupName "joywebapp" -ServerName "joydb" -ElasticPoolName "joyelastic"
foreach($db in $dbs){
Set-AzureRmSqlDatabaseBackupShortTermRetentionPolicy -ResourceGroupName $db.ResourceGroupName -ServerName $db.ServerName -DatabaseName $db.DatabaseName -RetentionDays 35
}

Face difficulties on registering the SitecoreGallery repository

Want to install Sitecore9.1, first of all, try to register the repository in PowerShell.After running the following command get an error. Why error raise? need help to resolve this issue.
Register-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2
Error:
PackageManagement\Register-PackageSource : Module Repository 'SitecoreGallery' exists.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:4173 char:17
+ ... $null = PackageManagement\Register-PackageSource #PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceExists: (Microsoft.Power...erPackageSource:RegisterPackageSource) [Register-Pack
ageSource], Exception
+ FullyQualifiedErrorId : PackageSourceExists,Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource
The error says that this repository already exists. First, check if it's registered properly:
PS C:\> Get-PSRepository
Name InstallationPolicy SourceLocation
---- ------------------ --------------
PSGallery Untrusted https://www.powershellgallery.com/api/v2/
SitecoreGallery Untrusted https://sitecore.myget.org/F/sc-powershell/api/v2
If it is registered with incorrect data, you can change it:
Set-PSRepository -Name SitecoreGallery -SourceLocation https://sitecore.myget.org/F/sc-powershell/api/v2

Cannot find an overload for "SoftwareIdentity"

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.