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

Ash 56 Reputation points
2022-03-27T00:30:09.133+00:00

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=4.0.0.0, 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.
19,666 questions
{count} votes

3 answers

Sort by: Most helpful
  1. T. Kujala 8,706 Reputation points
    2022-03-27T06:02:35.027+00:00

    Hi @bulldogcloud,

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

    https://github.com/Azure/CloudShell/issues/72

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

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

    7 people found this answer helpful.

  2. Devaraj G 2,091 Reputation points
    2022-03-27T13:18:55.057+00:00

    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:
    https://github.com/repo/Azure/CloudShell/issues/72

    0 comments No comments

  3. Khurram Rahim 1,841 Reputation points
    2023-02-08T19:20:32.7933333+00:00

    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