Azure 我正在尝试创建powershell脚本,以便将用户批量导入到企业应用程序,但不断收到错误

Azure 我正在尝试创建powershell脚本,以便将用户批量导入到企业应用程序,但不断收到错误,azure,powershell,azure-active-directory,Azure,Powershell,Azure Active Directory,下面是我已经编写和修改了好几次的代码,但仍然无法开始工作。任何帮助都将不胜感激。我不断收到以下错误: 获取AzureADUser:无法将参数绑定到参数'ObjectId',因为它为空**,**新建AzureADUserAppRoleAssignment:无法将参数绑定到参数'ObjectId',因为它为空。 # Assign the global values to the variables for the script. $app_name = "App Name" $app_role_

下面是我已经编写和修改了好几次的代码,但仍然无法开始工作。任何帮助都将不胜感激。我不断收到以下错误:

获取AzureADUser:无法将参数绑定到参数'ObjectId',因为它为空**,**新建AzureADUserAppRoleAssignment:无法将参数绑定到参数'ObjectId',因为它为空。

# 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

}'''

看起来在
Path\Users.txt
中可能有空行。尝试
$users=Get Content'Path\users.txt'|其中Object{$}
文本文件中没有空行,但我在尝试csv时收到相同的错误。请在此处显示
users.txt
文件和csv文件,否则我们无法帮助您。