Я пытаюсь создать сценарий powershell для массового импорта пользователей в корпоративное приложение, но получаю ошибки - PullRequest
0 голосов
/ 19 марта 2020

Вот код, который я написал и изменил несколько раз, но все еще не могу получить работу. Любая помощь будет принята с благодарностью. Я продолжаю получать следующие ошибки:

Get-AzureADUser : Cannot bind argument to parameter 'ObjectId' because it is null** and **New-AzureADUserAppRoleAssignment : Cannot bind argument to parameter 'ObjectId' because it is null.

# Assign the global values to the variables for the script.

$app_name = "App Name"

$app_role_name = "User"

$users = Get-Content 'Path\Users.txt'

$Credential=Get-StoredCredential -UserName #####

# Connect to Azure AD using Azure AD Powershell
Connect-AzureAD -Credential $Credential

# Get the user to assign, and the service principal for the app to assign to
foreach ($user in $users) {

$AADuser = Get-AzureADUser -ObjectId $user

$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"

$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }

# Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId $user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id

}'''
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...