Connect-Entra (Microsoft.Graph.Entra) 

Connect-Entra (Microsoft.Graph.Entra)

The Connect-Entra cmdlet is used to connect to Microsoft Entra PowerShell module. This module simplifies the migration of legacy scripts as it supports 98% of the retired Azure AD and MSOnline cmdlets. You must install Microsoft Entra PowerShell module to use this cmdlet. Else, you will receive the error: The term ‘Connect-Entra’ is not recognized as the name of a cmdlet, function, script file, or operable Program

NOTE: You can use the Connect-Entra cmdlet to connect both v1.0 (General Availability) and Entra beta PowerShell module.

This module supports several authentication scenarios depending on your use case such as: delegated (interactive) and app-only (noninteractive).

Syntax

Description

The ‘Connect-Entra’ cmdlet connects to Microsoft Entra ID with an authenticated account. It works for accounts with or without multi-factor authentication (MFA).

Examples

Example 1: Initiate a connection

This command connects the current PowerShell session to a Microsoft Entra ID tenant using credentials.

Example 2: Delegated access: Connect to Entra ID PowerShell session with required scopes

This example shows how to authenticate Microsoft Entra ID with scopes.

Example 3: Connect MS Entra with Tenant id

If you don’t specify the TenantId parameter, it will create a session with the last tenant you signed in or home tenant.

Example 4: Delegated access: Using an access token

This example shows how to authenticate to Microsoft Entra ID using an access token. For more information on how to get or create access token, see Request an access token

Example 5: Delegated access: Using device code flow

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code to authenticate. This example shows how to authenticate to Microsoft Entra ID with device. For more information, see Device Code flow

Example 6: App-only access: Using client credential with a Certificate thumbprint

This cmdlet connects Entra ID PowerShell session using a ApplicationId and CertificateThumbprint.

For more information on how to get or create CertificateThumbprint, see Authenticate with app-only access.

Example 7: App-only access: Using client credential with a certificate name

This cmdlet connects Entra ID PowerShell session using a CertificateName.

Example 8: App-only access: Using client credential with a certificate

This cmdlet connects Entra ID PowerShell session using a Certificate path.

Example 9: App-only access: Using client secret credentials –

This authentication method is ideal for background interactions.

Example 10: App-only access: Using managed identity: System-assigned managed identity

Uses an automatically managed identity on a service instance.

Example 11: Connecting to an environment or cloud

When you use Connect-Entra, you can choose to target other environments.

By default, Connect-Entra targets the global public cloud.

Example 12: Hides the welcome message

This example hides the welcome message.

Parameters

-CertificateThumbprint <System.String>

Specifies the certificate thumbprint of a digital public key X.509 certificate of a user account that has permission to perform this action.

-ClientId <System.String>

Specifies the application ID of the service principal.

-TenantId <System.String>

Specifies the ID of a tenant. If you don’t specify this parameter, the account is authenticated with the home tenant. You must specify the TenantId parameter to authenticate as a service principal or when using Microsoft account.

-AccessToken <SecureString>

Specifies a bearer token for Microsoft Entra service. Access tokens do time out and you have to handle their refresh.

-ClientTimeout <System.Double>

Sets the HTTP client timeout in seconds.

-ContextScope <ContextScope>

Determines the scope of authentication context. This ContextScope accepts Process for the current process, or CurrentUser for all sessions started by user.

-Environment <System.String>

The name of the national cloud environment to connect to. By default global cloud is used.

-NoWelcome <System.Management.Automation.SwitchParameter>

Hides the welcome message.

-Scopes <System.String[]>

An array of delegated permissions to consent to.

-UseDeviceCode <System.Management.Automation.SwitchParameter>

Use device code authentication instead of a browser control.

-Certificate <X509Certificate2>

An X.509 certificate supplied during invocation.

-CertificateSubjectName <System.String>

The subject distinguished name of a certificate. The certificate is retrieved from the current user’s certificate store.

-ClientSecretCredential <PSCredential>

The PSCredential object provides the application ID and client secret for service principal credentials.

-EnvironmentVariable <System.Management.Automation.SwitchParameter>

Allows for authentication using environment variables configured on the host machine.

-Identity <System.Management.Automation.SwitchParameter>

Sign-in using a managed identity

-ProgressAction <ActionPreference>

The ProgressAction parameter takes one of the ActionPreference enumeration values: SilentlyContinue, Stop, Continue, Inquire, Ignore,

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters.

Connect-Entra (Microsoft.Graph.Entra) 

by Kavya time to read: 5 min
0