发布于 2021-01-18 09:21:13
让我们假设您有以下文件:

左边是用户的用户名,右边是新管理器的用户名。
您可以使用下面的片段
#connecting to the Azure AD
Connect-AzureAD
#importing the CSV source which has the changes
$data = Import-Csv D:\Temp\Book1.csv
#Iterating through each row in the CSV
foreach ($row in $data)
{
#INFO in the Console
Write-Host "Updating the user :" $row.'User Username' " manager to " $row.'Manager Username' -ForegroundColor Yellow
#Updating the Manager
Set-AzureADUserManager -ObjectId (Get-AzureADUser -ObjectId $row.'User Username').Objectid -RefObjectId (Get-AzureADUser -ObjectId $row.'Manager Username').Objectid
#Completion info in the console for the specified row
Write-Host "Updated." -ForegroundColor Green
}解释:
步骤1:连接到Azure AD的
步骤2:导入需要大容量更新的CSV数据的
步骤3 :遍历每一行,使用Set-AzureADUserManager命令更新管理器字段
示例输出:

发布于 2021-01-17 00:01:37
Get-AzureADUserManager和Set-AzureADUserManager只接受ObjectID作为输入,类似于其他一些AzureAD cmdlet。
你需要有一个多步骤的方法来实现这个结果,下面是我要采取的步骤
$AllAzureADUser = Get-AzureADUser -AllObjectID的管理器字段(本质上这是Foreach循环)$AllAzureADUserWithManager = $AllAzureADUser | select *, @{ Name = "ManagerObjectId"; Expression = { Get-AzureADUserManager $_.ObjectId }}
ObjectId。因此,假设您迭代从CSV导入的对象,其中有targetUserUPN和targetManagerUPN作为列:
$TargetUserObjectId = $AllAzureADUserWithManager | Where {$_.UPN -eq $row.targetUserUPN} | select -ExpandProperty ObjectId
$TargetManagerObjectId = $AllAzureADUserWithManager | Where {$_.UPN -eq $row.targetManagerUPN} | select -ExpandProperty ObjectId
Set-AzureADUserManager -ObjectId $TargetUserObjectId -RefObjectId $TargetManagerObjectId如果您需要每天运行这一点,请考虑使用增量并导出到csv之前的运行,如果您有大量的用户,则筛选到所需的内容。
https://stackoverflow.com/questions/65738104
复制相似问题