|
| 1 | +# ------------------------------------------------------------------------------ |
| 2 | +# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information. |
| 3 | +# ------------------------------------------------------------------------------ |
| 4 | + |
1 | 5 | <# |
2 | 6 | .SYNOPSIS |
3 | 7 | Generates an object representing all the values contained in a certificate file that can be used in Entra ID for configuring CertificateUserIDs in Certificate-Based Authentication. |
|
8 | 12 | .PARAMETER Path |
9 | 13 | The path to the certificate file. The file can be in .cer or .pem format. |
10 | 14 |
|
| 15 | +.PARAMETER Certificate |
| 16 | + An X509Certificate2 object |
| 17 | +
|
11 | 18 | .PARAMETER CertificateMapping |
12 | 19 | The certificate mapping property to retrieve. Valid values are PrincipalName, RFC822Name, IssuerAndSubject, Subject, SKI, SHA1PublicKey, and IssuerAndSerialNumber. |
13 | 20 |
|
|
16 | 23 |
|
17 | 24 | This command retrieves all the possible certificate mappings and returns an object to represent them. |
18 | 25 |
|
| 26 | +.EXAMPLE |
| 27 | + PS > Get-MsIdCBACertificateUserIdFromCertificate -Certificate $cert |
| 28 | +
|
| 29 | + This command retrieves all the possible certificate mappings and returns an object to represent them. |
| 30 | +
|
19 | 31 | .EXAMPLE |
20 | 32 | PS > Get-MsIdCBACertificateUserIdFromCertificate -Path "C:\path\to\certificate.cer" -CertificateMapping Subject |
21 | 33 |
|
|
37 | 49 | #> |
38 | 50 |
|
39 | 51 | function Get-MsIdCBACertificateUserIdFromCertificate { |
40 | | - [CmdletBinding(HelpUri = 'https://azuread.github.io/MSIdentityTools/commands/Get-MsIdCBACertificateUserIdFromCertificate')] |
41 | 52 | param ( |
42 | | - [Parameter(Mandatory = $true)] |
| 53 | + [Parameter(Mandatory = $false)] |
43 | 54 | [string]$Path, |
44 | 55 | [Parameter(Mandatory = $false)] |
| 56 | + [System.Security.Cryptography.X509Certificates.X509Certificate2]$Certificate, |
| 57 | + [Parameter(Mandatory = $false)] |
45 | 58 | [ValidateSet("PrincipalName", "RFC822Name", "IssuerAndSubject", "Subject", "SKI", "SHA1PublicKey", "IssuerAndSerialNumber")] |
46 | 59 | [string]$CertificateMapping |
47 | 60 | ) |
@@ -191,7 +204,12 @@ function Get-MsIdCBACertificateUserIdFromCertificate { |
191 | 204 |
|
192 | 205 | function Main |
193 | 206 | { |
194 | | - $cert = Get-Certificate -filePath $Path |
| 207 | + $cert = $Certificate |
| 208 | + if ($null -eq $cert) |
| 209 | + { |
| 210 | + $cert = Get-Certificate -filePath $Path |
| 211 | + } |
| 212 | + |
195 | 213 | $mappings = Get-CertificateUserIds -cert $cert |
196 | 214 |
|
197 | 215 | if ($CertificateMapping -eq "") |
|
0 commit comments