not able to install modules

Hi,
when I use powershell 5.1 to install the azureAD module I get the following error
[pre]

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 'msonline'. 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], Exception + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage[/pre]
when running powershell 6 I'm able to install AzureAD but when I check get-module the AzureAD module is not listed when I run get-installedModule -Name AzureAD -Allversions I get this as feedback

[pre]

Version Name Repository Description ------- ---- ---------- ----------- 2.0.2.76 AzureAD PSGallery Azure Active Directory V2 General Availability Module.... [/pre] but when I run connect-azureAD (which would normally pops up the authentication windows to enter username password and mfa) this is not happening do you have any ideas on how to troubleshoot this?

Paul

Try this, run this in 5.1 and then try to install the module.

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

Doug you rock thanks for this

can you explain to me what this does exactly

Best regards

Paul

They dropped support for TLS 1.0, so you instructed powershell to use 1.2. See this thread.
Glad I could help.

another question
I’m preparing a script that is going to be shared with a couple of users.
and they need to have to install the required modules as well.
is there a way to test what the current security protocol state is?
this way I can integrate this in my checks that if current security protocol is not equal to
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
to run this?

It’s only an issue in 5.1. What’s the harm in adding this to the beginning of each of your scripts just in case? Even if it’s set, it won’t error. However, you could potentially check it like this, but surely there is a better way.

if([Net.ServicePointManager]::SecurityProtocol -notmatch 'tls12')
{
    [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}

Or

if(([Net.ServicePointManager]::SecurityProtocol -split ',').trim() -notcontains 'tls12')
{
    [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
}

thanks Doug,
the goal is to create a check.ps where all these things are checked and once a module is installed I don’t require to change the current settings

 

Paul