-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-AzureADDeviceIDFromCertificate.ps1
More file actions
36 lines (30 loc) · 1.14 KB
/
Get-AzureADDeviceIDFromCertificate.ps1
File metadata and controls
36 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function Get-AzureADDeviceIDFromCertificate {
<#
.SYNOPSIS
Used to pull the Azure Device ID from the provided Base64 certificate.
.DESCRIPTION
Used by the function app to pull the Azure Device ID from the provided Base64 certificate.
.NOTES
Author: Maxton Allen
Contact: @AzureToTheMax
Created: 2023-05-14
Updated: 2023-05-14
Version history:
1.0.0 - (2023-05-14) created
#>
param(
[parameter(Mandatory = $true, HelpMessage = "Specify a Base64 encoded value for which an Azure Device ID will be extracted.")]
[ValidateNotNullOrEmpty()]
[string]$Value
)
Process {
# Convert Value (cert) passed back to X502 Object
$X502 = [System.Security.Cryptography.X509Certificates.X509Certificate2]::New([System.Convert]::FromBase64String($Value))
# Get the Subject (issued to)
$Subject = $X502.Subject
# Remove the leading "CN="
$SubjectTrimed = $Subject.TrimStart("CN=")
# Handle return
Return $SubjectTrimed
}
}