如何在 PowerShell 中使用下面的输出中的 Enddate 来过滤此输出
$expiryApps = $appRegistrations | Where-Object { $_.PasswordCredentials.EndDate -lt $thresholdDate } | Select-Object DisplayName, objectID, PasswordCredentials
foreach($i in $expiryApps){
$ExpieredKey = Get-AzureADApplicationPasswordCredential -objectID $i.objectID
foreach($expiry in $ExpieredKey){
write-host $expiry
}
}
我得到这个输出,我需要在这里按结束日期过滤
class PasswordCredential {
CustomKeyIdentifier:
EndDate: 9/9/2023 6:30:00 PM
KeyId:
StartDate: 9/8/2023 6:30:00 PM
Value:
}
class PasswordCredential {
CustomKeyIdentifier:
EndDate: 3/6/2024 9:02:26 AM
KeyId:
StartDate: 9/8/2023 9:02:26 AM
Value:
}
如何在 PowerShell 中使用下面的输出中的 Enddate 来过滤此输出
我创建了一些将秘密
end dates
设置为 '2023-12-07'
的应用程序,以获取秘密。
申请
这是更新后的脚本,用于过滤带有结束日期的应用程序机密。
$thresholdDate = Get-Date "2023-12-07"
$appRegistrations = Get-AzureADApplication
foreach ($app in $appRegistrations) {
$PasswordCredentials = Get-AzureADApplicationPasswordCredential -ObjectId $app.ObjectId
foreach ($credential in $PasswordCredentials) {
$formattedEndDate = $credential.EndDate.ToString("MM/dd/yyyy")
if ($formattedEndDate -eq $thresholdDate.ToString("MM/dd/yyyy")) {
Write-Host "Application: $($app.DisplayName)"
Write-Host " PasswordCredential:"
Write-Host " EndDate: $($credential.EndDate)"
}
}
}
脚本将检查所有申请,如果结束日期匹配,则会显示该申请。
输出: