@@ -66,11 +66,45 @@ You cannot use multi-factor authentication or Microsoft account credentials to r
66
66
67
67
### Example 3: Connect a session as a service principal
68
68
```
69
- PS C:\> Connect-AzureAD -TenantId "xxxx-xxxx-xxxx-xxxx" -ApplicationId "xxxx-xxxx-xxxx-xxxx" -CertificateThumbprint "xxxx-xxxx-xxxx-xxxx"
69
+ # Login to Azure AD PowerShell With Admin Account
70
+ Connect-AzureAD
71
+
72
+ # Create the self signed cert
73
+ $currentDate = Get-Date
74
+ $endDate = $currentDate.AddYears(1)
75
+ $notAfter = $endDate.AddYears(1)
76
+ $pwd = "<password>"
77
+ $thumb = (New-SelfSignedCertificate -CertStoreLocation cert:\localmachine\my -DnsName com.foo.bar -KeyExportPolicy Exportable -Provider "Microsoft Enhanced RSA and AES Cryptographic Provider" -NotAfter $notAfter).Thumbprint
78
+ $pwd = ConvertTo-SecureString -String $pwd -Force -AsPlainText
79
+ Export-PfxCertificate -cert "cert:\localmachine\my\$thumb" -FilePath c:\temp\examplecert.pfx -Password $pwd
80
+
81
+ # Load the certificate
82
+ $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate("C:\temp\examplecert.pfx", $pwd)
83
+ $keyValue = [System.Convert]::ToBase64String($cert.GetRawCertData())
84
+
85
+
86
+ # Create the Azure Active Directory Application
87
+ $application = New-AzureADApplication -DisplayName "test123" -IdentifierUris "https://test123"
88
+ New-AzureADApplicationKeyCredential -ObjectId $application.ObjectId -CustomKeyIdentifier "Test123" -StartDate $currentDate -EndDate $endDate -Type AsymmetricX509Cert -Usage Verify -Value $keyValue
89
+
90
+ # Create the Service Principal and connect it to the Application
91
+ $sp=New-AzureADServicePrincipal -AppId $application.AppId
92
+
93
+ # Give the Service Principal Reader access to the current tenant (Get-AzureADDirectoryRole)
94
+ Add-AzureADDirectoryRoleMember -ObjectId 5997d714-c3b5-4d5b-9973-ec2f38fd49d5 -RefObjectId $sp.ObjectId
95
+
96
+ # Get Tenant Detail
97
+ $tenant=Get-AzureADTenantDetail
98
+ # Now you can login to Azure PowerShell with your Service Principal and Certificate
99
+ Connect-AzureAD -TenantId $tenant.ObjectId -ApplicationId $sp.AppId -CertificateThumbprint $thumb
100
+
70
101
```
71
102
72
103
This command authenticates the user to Azure Active Directory as a service principal.
73
104
105
+
106
+
107
+
74
108
## PARAMETERS
75
109
76
110
### -AadAccessToken
0 commit comments