![](/img/trans.png)
[英]How to remove identifierUris using PowerShell in Azure Active Directory Application
[英]Check if IdentifierUris exists in Microsoft Azure Active Directory Application using PowerShell
我正在使用以下PowerShell脚本创建Azure Active Directory应用程序
$appName = "data-factory-app"
$appURI = "www.datafactoryapp.com"
$appExists = Get-AzADApplication -DisplayName $appName
if (-not $appExists)
{
if (-not $appExists.IdentifierUris
New-AzADApplication -DisplayName $appName -IdentifierUris $appURI
}
else
{
Write-Output "Application Already Exists"
}
我正在对Display Name
进行检查,如果IdentifierUris
存在,但还需要对其进行检查,但找不到任何命令。 谁能帮忙
为此,我建议使用AzureAD PowerShell模块中的Get-AzureADApplication
cmdlet(cmdlet的形式为-AzureAD ),而不是Azure Azure 2.0模块中的cmdlet(其中cmdlet的形式为-AzAD )。
使用此cmdlet,可以像在Azure AD Graph API $ filter参数中一样指定过滤器 ,并在一个请求中获得所需的内容。
要获得具有给定显示名称或与您给定的显示名称匹配的任何标识符URI(技术上是列表)的所有Application对象,可以执行以下操作:
$appName = "data-factory-app"
$appURI = "www.datafactoryapp.com"
$filter = "displayName eq '{0}' or identifierUris/any(u:u eq '{1}')" -f $appName, $appURI
$appExists = Get-AzureADApplication -Filter $filter
if (-not $appExists) {
# No application exists with that display name or identifier URI
} else {
# An application already exists with that display name or identifier URI!
}
编辑:如果由于某种原因必须使用Azure PowerShell模块(Az),则需要进行两个单独的调用来检查:
$appName = "data-factory-app"
$appURI = "www.datafactoryapp.com"
$appExistsWithDisplayName = Get-AzADApplication -DisplayName $appName
if (-not $appExistsWithDisplayName) {
$appExistsWithIdentifierUri = Get-AzADApplication -IdentifierUri $appURI
if (-not $appExistsWithIdentifierUri)) {
# No application exists with that display name or identifier URI
} else {
# An application already exists with that identifier URI
}
} else {
# An application already exists with that display name
}
我自己无法对此进行测试,但这可能会有所帮助:
$appName = "data-factory-app"
$appURI = "www.datafactoryapp.com"
$appExists = Get-AzADApplication -DisplayName $appName
if (-not $appExists) {
Write-Output "Application '$appName' does not exist"
# create it here?
# see https://docs.microsoft.com/en-us/powershell/module/az.resources/new-azadapplication?view=azps-2.0.0
}
else {
Write-Output "Application already exists, checking IdentifierUris"
if (-not $appExists.IdentifierUris -or @($appExists.IdentifierUris) -notcontains $appURI ) {
Write-Output "Updating Application IdentifierUris"
$appExists | Update-AzADApplication -IdentifierUri $appURI
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.