1- ---
1+ ---
22external help file : Microsoft.Graph.Authentication.dll-Help.xml
33Module Name : Microsoft.Graph.Authentication
44online version : https://learn.microsoft.com/en-us/powershell/module/microsoft.graph.authentication/connect-mggraph
@@ -8,59 +8,146 @@ schema: 2.0.0
88# Connect-MgGraph
99
1010## SYNOPSIS
11- {{ Fill in the Synopsis }}
11+ Microsoft Graph PowerShell supports two types of authentication: delegated and app-only access. There are a number of cmdlets that can be used to manage the different parameters required during authentication, for example, environment, application ID, and certificate.
1212
1313## SYNTAX
1414
1515### UserParameterSet (Default)
1616```
1717Connect-MgGraph [[-Scopes] <String[]>] [[-ClientId] <String>] [-TenantId <String>]
18- [-ContextScope <ContextScope>] [-Environment <String>] [-UseDeviceCode] [-ClientTimeout <Double>] [-NoWelcome]
19- [-Break] [ <CommonParameters>]
18+ [-ContextScope <ContextScope>] [-Environment <String>] [-UseDeviceCode] [-ClientTimeout <Double>]
19+ [<CommonParameters>]
2020```
2121
2222### AppCertificateParameterSet
2323```
2424Connect-MgGraph [-ClientId] <String> [[-CertificateSubjectName] <String>] [[-CertificateThumbprint] <String>]
2525 [-Certificate <X509Certificate2>] [-TenantId <String>] [-ContextScope <ContextScope>] [-Environment <String>]
26- [-ClientTimeout <Double>] [-NoWelcome] [-Break] [ <CommonParameters>]
26+ [-ClientTimeout <Double>] [<CommonParameters>]
2727```
2828
2929### IdentityParameterSet
3030```
3131Connect-MgGraph [[-ClientId] <String>] [-ContextScope <ContextScope>] [-Environment <String>]
32- [-ClientTimeout <Double>] [-Identity] [-NoWelcome] [-Break] [ <CommonParameters>]
32+ [-ClientTimeout <Double>] [-Identity] [<CommonParameters>]
3333```
3434
3535### AppSecretCredentialParameterSet
3636```
3737Connect-MgGraph [-ClientSecretCredential <PSCredential>] [-TenantId <String>] [-ContextScope <ContextScope>]
38- [-Environment <String>] [-ClientTimeout <Double>] [-NoWelcome] [-Break] [ <CommonParameters>]
38+ [-Environment <String>] [-ClientTimeout <Double>] [<CommonParameters>]
3939```
4040
4141### AccessTokenParameterSet
4242```
43- Connect-MgGraph [-AccessToken] <SecureString> [-Environment <String>] [-ClientTimeout <Double>] [-NoWelcome]
44- [-Break] [ <CommonParameters>]
43+ Connect-MgGraph [-AccessToken] <SecureString> [-Environment <String>] [-ClientTimeout <Double>]
44+ [<CommonParameters>]
4545```
4646
4747### EnvironmentVariableParameterSet
4848```
4949Connect-MgGraph [-ContextScope <ContextScope>] [-Environment <String>] [-ClientTimeout <Double>]
50- [-EnvironmentVariable] [-NoWelcome] [-Break] [ <CommonParameters>]
50+ [-EnvironmentVariable] [<CommonParameters>]
5151```
5252
5353## DESCRIPTION
54- {{ Fill in the Description }}
54+ You must invoke Connect-MgGraph before any commands that access Microsoft Graph. This cmdlet gets the access token using the Microsoft Authentication Library
5555
5656## EXAMPLES
5757
58- ### Example 1
58+ ### Example 1: Delegated access: Using interactive authentication, where you provide the scopes that you require during your session
59+ ``` powershell
60+ PS C:\> Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
61+ ```
62+
63+ This example shows how to authenticate to graph with scopes.
64+
65+ ### Example 2: Delegated access: Using device code flow
66+ ``` powershell
67+ PS C:\> Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All" -UseDeviceAuthentication
68+ ```
69+
70+ This example shows how to authenticate to graph with scopes and device.
71+
72+ ### Example 3: Delegated access: Using your own access token
73+ ``` powershell
74+ PS C:\> Connect-MgGraph -AccessToken $AccessToken
75+ ```
76+
77+ This example shows how to authenticate to graph using an access token.
78+
79+ ### Example 4: Delegated access: custom application for Microsoft Graph PowerShell
80+ ``` powershell
81+ PS C:\> Connect-MgGraph -ClientId <YOUR_NEW_APP_ID> -TenantId <YOUR_TENANT_ID>
82+ ```
83+
84+ Follow this [ link] ( https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph ) for more information on the steps for creating custom applications.
85+
86+ ### Example 5: App-only access: Using client credential with a certificate - Certificate Thumbprint
87+ ``` powershell
88+ PS C:\> Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -CertificateThumbprint "YOUR_CERT_THUMBPRINT"
89+ ```
90+
91+ Follow this [ link] ( https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph ) for more information on how to load the certificate.
92+
93+ ### Example 6: App-only access: Using client credential with a certificate - Certificate name
94+ ``` powershell
95+ PS C:\> Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -CertificateName "YOUR_CERT_SUBJECT"
96+ ```
97+
98+ Follow this [ link] ( https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph ) for more information on how to load the certificate.
99+
100+ ### Example 7: App-only access: Using client credential with a certificate - Certificate
101+ ``` powershell
102+ PS C:\> $Cert = Get-ChildItem Cert:\LocalMachine\My\$CertThumbprint
103+ PS C:\> Connect-MgGraph -ClientId "YOUR_APP_ID" -TenantId "YOUR_TENANT_ID" -Certificate $Cert
104+ ```
105+
106+ Follow this [ link] ( https://learn.microsoft.com/en-us/powershell/microsoftgraph/authentication-commands?view=graph-powershell-1.0#using-connect-mggraph ) for more information on how to load the certificate.
107+
108+ ### Example 8: Using client secret credentials
59109``` powershell
60- PS C:\> {{ Add example code here }}
110+ PS C:\> $ClientSecretCredential = Get-Credential -Credential "Client_Id"
111+ # Enter client_secret in the password prompt.
112+ PS C:\> Connect-MgGraph -TenantId "Tenant_Id" -ClientSecretCredential $ClientSecretCredential
61113```
62114
63- {{ Add example description here }}
115+ This authentication method is ideal for background interactions. It does not require a user to physically sign in.
116+
117+ ### Example 9: Using managed identity: System-assigned managed identity
118+ ``` powershell
119+ PS C:\> Connect-MgGraph -Identity
120+ ```
121+
122+ Uses an automatically managed identity on a service instance. The identity is tied to the lifecycle of a service instance.
123+
124+ ### Example 10: Using managed identity: User-assigned managed identity
125+ ``` powershell
126+ PS C:\> Connect-MgGraph -Identity -ClientId "User_Assigned_Managed_identity_Client_Id"
127+ ```
128+
129+ Uses a user created managed identity as a standalone Azure resource.
130+
131+ ### Example 11: Connecting to an environment or cloud
132+ ``` powershell
133+ PS C:\> Get-MgEnvironment
134+ Name AzureADEndpoint GraphEndpoint Type
135+ ---- --------------- ------------- ----
136+ China https://login.chinacloudapi.cn https://microsoftgraph.chinacloudapi.cn Built-in
137+ Global https://login.microsoftonline.com https://graph.microsoft.com Built-in
138+ USGov https://login.microsoftonline.us https://graph.microsoft.us Built-in
139+ USGovDoD https://login.microsoftonline.us https://dod-graph.microsoft.us Built-in
140+ PS C:\> Connect-MgGraph -Environment USGov
141+ ```
142+
143+ When you use Connect-MgGraph, you can choose to target other environments. By default, Connect-MgGraph targets the global public cloud.
144+
145+ ### Example 12: Connecting to an environment as a different identity
146+ ``` powershell
147+ PS C:\> Connect-MgGraph -ContextScope Process
148+ ```
149+
150+ To connect as a different identity other than CurrentUser, specify the -ContextScope parameter with the value Process.
64151
65152## PARAMETERS
66153
@@ -80,21 +167,6 @@ Accept pipeline input: False
80167Accept wildcard characters : False
81168` ` `
82169
83- ### -Break
84- Wait for .NET debugger to attach
85-
86- ` ` ` yaml
87- Type : SwitchParameter
88- Parameter Sets : (All)
89- Aliases :
90-
91- Required : False
92- Position : Named
93- Default value : None
94- Accept pipeline input : False
95- Accept wildcard characters : False
96- ` ` `
97-
98170### -Certificate
99171An X.509 certificate supplied during invocation.
100172
@@ -264,21 +336,6 @@ Accept pipeline input: False
264336Accept wildcard characters : False
265337` ` `
266338
267- ### -NoWelcome
268- Hides the welcome message.
269-
270- ` ` ` yaml
271- Type : SwitchParameter
272- Parameter Sets : (All)
273- Aliases :
274-
275- Required : False
276- Position : Named
277- Default value : None
278- Accept pipeline input : False
279- Accept wildcard characters : False
280- ` ` `
281-
282339### -Scopes
283340An array of delegated permissions to consent to.
284341
0 commit comments