'Connect-AzureAD' is not recognized as a name of a cmdlet

Ash 56 Reputation points

I'm following an online course on Azure and cannot figure out why this command won't run in the Cloud Shell. Can someone please help?

Connect-AzureAD: The term 'Connect-AzureAD' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I ran "Install-Module AzureAD" which installed ok.

Import-Module AzureAD shows the following:

Import-Module: Could not load file or assembly 'System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
17,598 questions
{count} votes

3 answers

Sort by: Most helpful
  1. T. Kujala 8,676 Reputation points

    Hi @bulldogcloud,

    This is a typical situation when you run the command inside CloudShell.


    I recommend you to use this commands in your own workstation.

    PS> Install-Module AzureAD
    PS> Import-Module AzureAD
    PS> Connect AzureAD

    5 people found this answer helpful.
    0 comments No comments

  2. Devaraj G 2,176 Reputation points

    PowerShell cloudshell runs with few limitations when executing AzureAD modules.

    Currently, AzureAD.Standard.Preview, a preview version of .NET Standard-based, module is available. This module provides the same functionality as AzureAD.

    Details about the workaround:

    0 comments No comments

  3. Khurram Rahim 1,836 Reputation points

    The error message you're encountering is indicating that the AzureAD module is missing a required assembly, System.Windows.Forms, which is needed to run Connect-AzureAD.

    The AzureAD module is not supported in the Azure Cloud Shell, which is a limited environment for running scripts. To use the Connect-AzureAD cmdlet, you'll need to run it on a computer that has the AzureAD module installed and the required dependencies. You can use the Azure CLI or Azure Portal to manage your Azure resources instead.

    Alternatively, you can try running the script locally on a machine that has the required dependencies installed.

    0 comments No comments