我想创建一个包含所有 Azure AD 应用程序的输出,其中 returns a) 所有列表 b) 即将到期的应用程序列表
I want to create an output with all the Azure AD applications, which returns a)listing of all b) listing of expiring apps
这是我目前所知道的,但是 $expirationlist 没有 return 支持使用 $expirationlist 变量到期的所有应用程序的列表。
$date= get-date
$expirationdate= $date.AddDays(30)
$ADApplications = Get-AzADApplication
$result = foreach ($application in $ADApplications)
{
$credentials = Get-AzADAppCredential -ApplicationId
$application.ApplicationId
$StartDate = $credentials.StartDate
$EndDate = $credentials.EndDate
[PSCustomObject]@{
ApplicationName = $application.DisplayName
ApplicationID = $application.ApplicationId
ObjectID = $application.ObjectId
CreationDate = $StartDate
ExpirationDate = $EndDate
}
if($EndDate -lt $expirationdate)
{
$expirationlist = [PSCustomObject]@{
ApplicationName = $application.DisplayName
ApplicationID = $application.ApplicationId
ObjectID = $application.ObjectId
CreationDate = $StartDate
ExpirationDate = $EndDate
}
}
}
$expirationlist
错误来自使用 $null
键转换 PSCustomObject
:
示例:
PS /> [pscustomobject]@{ $null = 'asd' }
A null key is not allowed in a hash literal.
At line:1 char:19
+ [pscustomobject]@{ $null = 'asd' }
+ ~~~~~
+ CategoryInfo : InvalidOperation: (System.Collecti...deredDictionary:OrderedDictionary) [], RuntimeException
+ FullyQualifiedErrorId : InvalidNullKey
由于未定义这些变量,它们基本上为空:
$ApplicationName
、$ApplicationID
、$ObjectID
等
试试这个,它应该可以工作,我还添加了一个小的效率改进:
$ADApplications = Get-AzADApplication
$result = foreach ($application in $ADApplications)
{
$credentials = Get-AzADAppCredential -ApplicationId $application.ApplicationId
foreach($credential in $credentials)
{
$StartDate = $credential.StartDate
$EndDate = $credential.EndDate
[PSCustomObject]@{
ApplicationName = $application.DisplayName
ApplicationID = $application.ApplicationId
ObjectID = $application.ObjectId
CreationDate = $StartDate
ExpirationDate = $EndDate
}
}
}
$result | Where-Object {[datetime]$_.EndDate -lt [datetime]::Now.AddDays(30)}
这是我目前所知道的,但是 $expirationlist 没有 return 支持使用 $expirationlist 变量到期的所有应用程序的列表。
$date= get-date
$expirationdate= $date.AddDays(30)
$ADApplications = Get-AzADApplication
$result = foreach ($application in $ADApplications)
{
$credentials = Get-AzADAppCredential -ApplicationId
$application.ApplicationId
$StartDate = $credentials.StartDate
$EndDate = $credentials.EndDate
[PSCustomObject]@{
ApplicationName = $application.DisplayName
ApplicationID = $application.ApplicationId
ObjectID = $application.ObjectId
CreationDate = $StartDate
ExpirationDate = $EndDate
}
if($EndDate -lt $expirationdate)
{
$expirationlist = [PSCustomObject]@{
ApplicationName = $application.DisplayName
ApplicationID = $application.ApplicationId
ObjectID = $application.ObjectId
CreationDate = $StartDate
ExpirationDate = $EndDate
}
}
}
$expirationlist
错误来自使用 $null
键转换 PSCustomObject
:
示例:
PS /> [pscustomobject]@{ $null = 'asd' }
A null key is not allowed in a hash literal.
At line:1 char:19
+ [pscustomobject]@{ $null = 'asd' }
+ ~~~~~
+ CategoryInfo : InvalidOperation: (System.Collecti...deredDictionary:OrderedDictionary) [], RuntimeException
+ FullyQualifiedErrorId : InvalidNullKey
由于未定义这些变量,它们基本上为空:
$ApplicationName
、$ApplicationID
、$ObjectID
等
试试这个,它应该可以工作,我还添加了一个小的效率改进:
$ADApplications = Get-AzADApplication
$result = foreach ($application in $ADApplications)
{
$credentials = Get-AzADAppCredential -ApplicationId $application.ApplicationId
foreach($credential in $credentials)
{
$StartDate = $credential.StartDate
$EndDate = $credential.EndDate
[PSCustomObject]@{
ApplicationName = $application.DisplayName
ApplicationID = $application.ApplicationId
ObjectID = $application.ObjectId
CreationDate = $StartDate
ExpirationDate = $EndDate
}
}
}
$result | Where-Object {[datetime]$_.EndDate -lt [datetime]::Now.AddDays(30)}