导出 Entra ID 应用程序注册 证书和机密到期报告
您需要一种快速的方法来显示所有 Entra ID 应用程序注册证书或机密及其到期日期。如果您在此之前未续订,则与应用程序的连接将不再有效。因此,重要的是不要让应用程序注册的证书或机密过期。在本文中,你将了解如何使用 Microsoft Graph PowerShell 将 Entra ID 应用注册及其证书和客户端密钥到期日期导出到报告中。
检查 Microsoft Entra 中的应用程序注册证书和机密过期日期
要检查应用程序注册证书或密钥是否已过期,请执行以下步骤:
- 登录到微软 Entra 管理中心
- 扩张身份 > 应用程序 > 应用程序注册
- 选择所有应用程序
- 单击应用您想要检查证书过期状态的
在我们的示例中,我们有 4 个应用程序,应用程序 Kairo 显示证书和机密已过期。
- 点击证书和秘密
- 选择证书或者客户秘密
在我们的示例中,应用程序 Kairo 仅具有客户端机密,没有证书。一个客户端密钥已过期(红色),另一个客户端密钥即将过期(橙色)。
要续订 Microsoft Entra ID 中的客户端密钥,我们需要创建新的客户端密钥并删除过期的客户端密钥。
浏览所有申请并检查证书或客户端密钥的到期日期(包括其状态)需要时间。因此,最好的方法是运行 PowerShell 脚本来创建包含所有信息的报告。
让我们看看下一步的 PowerShell 脚本。
使用 PowerShell 获取 Entra ID 应用程序注册证书和机密到期日期
获取所有应用程序注册及其证书和机密过期日期的一个好方法是使用 Microsoft Graph PowerShell。
Get-AppCertSecStatus.ps1 脚本将获取 Microsoft Entra ID 中的所有应用注册并收集以下详细信息:
- 应用程序名称
- 应用程序ID
- 凭证名称
- 登录类型
- 创建日期时间
- 开始日期时间
- 结束日期时间
- 过期状态
- 验证类型
- 剩余天数
- 所有者
- 所有者ID
步骤 1. 准备 Get-AppCertSecStatus PowerShell 脚本
上创建两个文件夹(中:)驾驶:
- 温度
- 脚本
下载 Get-AppCertSecStatus.ps1 PowerShell 脚本并将其放入C:脚本文件夹。该脚本会将 CSV 文件导出到C:温度文件夹。
确保文件未被阻止,以防止运行脚本时出现错误。请阅读文章运行 PowerShell 脚本时出现未数字签名错误来了解更多信息。
另一种选择是将以下代码复制并粘贴到记事本中。给它起个名字获取AppCertSecStatus.ps1并将其放置在C:脚本文件夹。
<#
.SYNOPSIS
Get-AppCertSecStatus.ps1
.DESCRIPTION
Export Entra ID app registrations certificates and secrets expiration date.
.LINK
www.alitajran.com/export-entra-id-app-registrations-certificates-secrets/
.NOTES
Written by: ALI TAJRAN
Website: www.alitajran.com
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 01/14/2024 - Initial version
V1.10, 04/30/2024 - Added AppId property to the results
#>
# CSV file path to export
$CsvPath = "C:tempAppRegistrationsReport.csv"
# Connect to MgGraph with necessary scopes
Connect-MgGraph "Directory.Read.All", "Application.Read.All"
# Initialize a List to store the data
$Report = [System.Collections.Generic.List[Object]]::new()
# Get properties
$Properties = @(
'AppId',
'DisplayName',
'PasswordCredentials',
'KeyCredentials',
'Id',
'SignInAudience',
'CreatedDateTime'
)
# Get Applications
$Apps = Get-MgApplication -All -Property $Properties | Select-Object $Properties
foreach ($App in $Apps) {
# Get Owner information
$Owner = Get-MgApplicationOwner -All -ApplicationId $App.Id
$Username = if ($Owner) { $Owner.AdditionalProperties.userPrincipalName -join ';' } else { "N/A" }
$OwnerID = if ($Owner) { $Owner.Id -join ';' } else { "N/A" }
# Check application for client secret
if ($null -ne $App.PasswordCredentials) {
foreach ($Creds in $App.PasswordCredentials) {
# Calculate days left until expiration
$DaysLeft = ($Creds.EndDateTime - (Get-Date)).Days
# Create custom object for client secret results
$ReportLine = [PSCustomObject]@{
ApplicationName = $App.DisplayName
ApplicationID = $App.AppId
CredentialName = $Creds.DisplayName
SignInType = $App.SignInAudience
CreatedDateTime = $App.CreatedDateTime
StartDateTime = $Creds.StartDateTime
EndDateTime = $Creds.EndDateTime
ExpireStatus = if ($Creds.EndDateTime -lt (Get-Date)) { "Expired" } else { "Not expired" }
AuthType = "Client_Secret"
DaysLeft = $DaysLeft
Owner = $Username
OwnerID = $OwnerID
}
# Add the report line to the List
$Report.Add($ReportLine)
}
}
# Check application for certificate
if ($null -ne $App.KeyCredentials) {
foreach ($Cert in $App.KeyCredentials) {
# Calculate days left until expiration
$DaysLeft = ($Cert.EndDateTime - (Get-Date)).Days
# Create custom object for certificate results
$ReportLine = [PSCustomObject]@{
ApplicationName = $App.DisplayName
ApplicationID = $App.AppId
CredentialName = $Cert.DisplayName
SignInType = $App.SignInAudience
CreatedDateTime = $App.CreatedDateTime
StartDateTime = $Cert.StartDateTime
EndDateTime = $Cert.EndDateTime
ExpireStatus = if ($Cert.EndDateTime -lt (Get-Date)) { "Expired" } else { "Not expired" }
AuthType = "Certificate"
DaysLeft = $DaysLeft
Owner = $Username
OwnerID = $OwnerID
}
# Add the report line to the List
$Report.Add($ReportLine)
}
}
}
# Sort the results based on DaysLeft
$Report = $Report | Sort-Object -Property DaysLeft
# Export to CSV file
$Report | Export-Csv $CsvPath -Encoding utf8 -NoTypeInformation
# Out-GridView
$Report | Out-GridView -Title "Microsoft Entra ID app registrations report"
- 21号线:编辑 CSV 文件路径
步骤 2. 安装 Microsoft Graph PowerShell
以管理员身份运行 Windows PowerShell 并安装 Microsoft Graph PowerShell。
Install-Module Microsoft.Graph -Force
重要的:在运行 cmdlet 或脚本之前,请务必更新到最新的 Microsoft Graph PowerShell 模块版本,以防止出现错误和不正确的结果。
步骤 3. 运行 Get-AppCertSecStatus PowerShell 脚本
使用 PowerShell 获取所有 Entra ID 应用程序注册证书和机密到期日期,包括其状态。
运行以下命令来运行脚本 Get-AppCertSecStatus.ps1。
c:scripts.Get-AppCertSecStatus.ps1
一个网格视图将显示您需要的所有信息。
步骤 4. 打开 Entra ID 应用程序注册报告
Get-AppCertSecStatus.ps1 PowerShell 脚本将所有应用程序注册及其证书和客户端密钥过期状态导出到 CSV 文件。
找到文件应用程序注册报告.csv在路径中C:温度。
使用您喜欢的应用程序打开 CSV 文件。在我们的示例中,它是 Microsoft Excel。
Entra ID 应用程序注册证书和客户端密钥过期报告看起来很棒。
结论
您了解了如何使用 Microsoft Graph PowerShell 导出 Entra ID 应用注册证书和机密。运行该脚本,它将收集所有信息并将其导出到 CSV 文件报告。确保在证书或客户端密钥过期之前续订证书或客户端密钥,以便与应用程序的连接保持完整。
您喜欢这篇文章吗?您可能还喜欢导出 Microsoft 365 非活动用户报告。不要忘记关注我们并分享这篇文章。
