简体   繁体   中英

Powershell 6.2.3 unable to import AzureAd module

I am getting the below error when importing the "AzureAD" powershell module. I have installed the module, unable to import it. I have checked to see if there are any prerequisites required, nothing mentioned in GitHub.

Earlier, I was able to install and import "AZ" module.

UPDATE : Resolved one dependency by copying the system.windows.forms.dll, but more runtime errors... 在此处输入图片说明

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

VERBOSE: Loading module from path 'C:\\Program Files\\PowerShell\\Modules\\AzureAd\\2.0.2.76\\AzureAd.psd1'. VERBOSE: Loading 'FormatsToProcess' from path 'C:\\Program Files\\PowerShell\\Modules\\AzureAd\\2.0.2.76\\AzureAD.Format.ps1xml'. VERBOSE: Populating RepositorySourceLocation property for module AzureAd. VERBOSE: Loading module from path 'C:\\Program Files\\PowerShell\\Modules\\AzureAd\\2.0.2.76\\Microsoft.Open.Azure.AD.CommonLibrary.dll'. Import-Module : Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified. At line:1 char:1 + Import-Module -Name AzureAd -Scope Global -Verbose + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.ImportModuleCommand

Which .NET version are you using? You may need to update it as this was an issue with older versions. If that doesn't work you can remove the dependency on System.Runtime.InteropServices.RuntimeInformation to get rid of the error in your screenshot.

It seems that the AzureAD Module is not compatible with PowerShell Core due to the WinForms dependency. I have tried both 7.0.0 and 6.2.4 which did not work

However you can install it using the Desktop version of PowerShell. This version works for me.

PS C:\Windows\system32> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.18362.752
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.18362.752
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Run elevated

Install-Module AzureAD

And then move on...

Import-Module -Name AzureAD

$creds = Get-Credential -Message "Credentials to connect to Azure AD"
Connect-AzureAD -Credential $creds

Get-AzureADCurrentSessionInfo 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM