I was trying to connect to Azure AD and run an MFA report to investigate a reported authentication problem. On a Windows Server 2019 server, I encountered the following errors:
PowerShell 9 lines Copy 1
2
3
4
5
6
7
8
9
PS C: \ Windows \ system32 > Install-Module MSOnline
WARNING : Unable to resolve package source '<a href="https://www.powershellgallery.com/api/v2/">https://www.powershellgallery.com/api/v2/</a>' .
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
PowerShell 9 lines Copy 1
2
3
4
5
6
7
8
9
PS C: \ Windows \ system32 > Install-Module -Name PowerShellGet -Force
WARNING : Unable to resolve package source '<a href="https://www.powershellgallery.com/api/v2/">https://www.powershellgallery.com/api/v2/</a>' .
PackageManagement \ Install-Package : No match was found for the specified search criteria and module name 'PowerShellGet' . 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
Installing the modules The server had direct outbound Internet access. To resolve the issue and install the MSOnline module, I ran the following commands in PowerShell:
PowerShell 5 lines Copy 1
2
3
4
5
[ System.Net.WebRequest ]:: DefaultWebProxy = [ System.Net.WebRequest ]:: GetSystemWebProxy ()
[ System.Net.WebRequest ]:: DefaultWebProxy . Credentials = [ System.Net.CredentialCache ]:: DefaultNetworkCredentials
[ Net.ServicePointManager ]:: SecurityProtocol = [ Net.SecurityProtocolType ]:: Tls12
Install-Module -Name PowerShellGet -Force -Verbose -Debug -Scope AllUsers
Install-Module MSOnline
Checking MFA status After running those commands, Connect-MsolService worked and I could use Get-MsolUser to check the MFA status:
PowerShell 2 lines Copy 1
2
$usercheck = "[email protected] "
Get-MsolUser -UserPrincipalName $usercheck | select DisplayName , UserPrincipalName , @ { N = "MFA Status" ; E ={ if ( $_ . StrongAuthenticationMethods . IsDefault -eq $true ) {( $_ . StrongAuthenticationMethods | Where IsDefault -eq $True ). MethodType } else { "Disabled" }}} | FT -AutoSize
Older post PowerShell: New-MigrationBatch for Exchange Online migration
Newer post Certification: Microsoft Azure Fundamentals AZ-900