如何通过Powershell为新的Azure AD应用程序配置预授权应用程序?

如何通过Powershell为新的Azure AD应用程序配置预授权应用程序?,azure,powershell,azure-active-directory,azure-powershell,Azure,Powershell,Azure Active Directory,Azure Powershell,我已经通过Powershell创建了一个新的Azure AD应用程序,但在配置预授权应用程序时遇到了问题。该模型包括记录的3个属性。我不使用扩展,这就是为什么我只为AppId和权限分配了一个值。但是只是为了看看错误的原因,我也给扩展分配了相同的结果,并且总是得到相同的错误 Set-AzureADApplication : Error occurred while executing SetApplication Code: Request_BadRequest Message: A value

我已经通过Powershell创建了一个新的Azure AD应用程序,但在配置预授权应用程序时遇到了问题。该模型包括记录的3个属性。我不使用扩展,这就是为什么我只为AppId和权限分配了一个值。但是只是为了看看错误的原因,我也给扩展分配了相同的结果,并且总是得到相同的错误

Set-AzureADApplication : Error occurred while executing SetApplication 
Code: Request_BadRequest
Message: A value without a type name was found and no expected type is available. When the model is specified, each value in the payload must have a type which can be either 
specified in the payload, explicitly by the caller or implicitly inferred from the parent value.
你可以在下面找到我的代码

$preAuthorizedApplication = New-Object -TypeName "Microsoft.Open.AzureAD.Model.PreAuthorizedApplication"
$preAuthorizedApplication.AppId = $myApiAppRegistrationResultAppId

$preAuthorizedApplicationPermissons = New-Object -TypeName "Microsoft.Open.AzureAD.Model.PreAuthorizedApplicationPermission" 
$preAuthorizedApplicationPermissons.AccessGrants = @($oauth2Permission.Id) # I have tried $oauth2Permission.Value also but nothing changed
$preAuthorizedApplicationPermissons.DirectAccessGrant = "True"
$preAuthorizedApplication.Permissions = $preAuthorizedApplicationPermissons

# Update the Application object
Set-AzureADApplication -ObjectId $appRegistration.ObjectId -PreAuthorizedApplications @($preAuthorizedApplication)

发生此错误的原因是
-PreAuthorizedApplications
的数据类型是
系统.Collections.Generic.List``1[Microsoft.Open.AzureAD.Model.PreAuthorizedApplication]
并且您在
设置AzureADApplication
命令中传递了错误的数据类型。您可以执行以下类似代码的操作:

$preAuthorizedApplications = New-Object 'System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.PreAuthorizedApplication]'
$preAuthorizedApplications.Add($preAuthorizedApplication)

我在这样更改代码之前就已经尝试过了,但还是出现了同样的错误。
$preAuthorizedApp.Permissions=New Object-TypeName System.Collections.Generic.List[Microsoft.Open.AzureAD.Model.PreAuthorizedApplicationPermission]$preAuthorizedApp.Permissions.Add($PreAuthorizedApplicationPermission)$preAuthorizedApps=新对象系统.Collections.Generic.List[Microsoft.Open.AzureAD.Model.preAuthorizedApps]$preAuthorizedApps.Add($preAuthorizedApps)Set-AzureADApplication-ObjectId$appRegistration.ObjectId-PreAuthorizedApplications$preAuthorizedApps
缺少一些配置。但是,传递预授权应用程序的正确方法是响应。我在这里发现的信息表明,未来尚未实现。您是否尝试过配置预授权应用程序?