首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >大容量更改管理器字段的AzureAD Powershell脚本

大容量更改管理器字段的AzureAD Powershell脚本
EN

Stack Overflow用户
提问于 2021-01-15 14:40:36
回答 2查看 4.4K关注 0票数 0
  1. 我的目标是拥有一个Powershell脚本,它可以导入CSV来批量更改AzureAD中的用户管理器字段。CSV将有2列,一列与用户,另一列与他们的经理。
  2. 我已经找到了将所有用户从AzureAD导出到CSV的脚本,但是这并不包含管理器字段的列标题。我找到了一个AzureAD脚本,可以使用objectID更改manager字段,但这很麻烦,所以理想情况下,我可以为manager字段使用电子邮件地址。
  3. 我没有代码可以展示,这些都是我找到的非常基本的脚本,但我充其量只是一个非Powershell用户。
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-01-18 09:21:13

让我们假设您有以下文件:

左边是用户的用户名,右边是新管理器的用户名。

您可以使用下面的片段

代码语言:javascript
复制
#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命令更新管理器字段

示例输出:

票数 0
EN

Stack Overflow用户

发布于 2021-01-17 00:01:37

Get-AzureADUserManager和Set-AzureADUserManager只接受ObjectID作为输入,类似于其他一些AzureAD cmdlet。

你需要有一个多步骤的方法来实现这个结果,下面是我要采取的步骤

  1. 获取所有Azure广告用户,例如$AllAzureADUser = Get-AzureADUser -All
  2. 使用计算的属性来填充基于您迭代的用户的ObjectID的管理器字段(本质上这是Foreach循环)

$AllAzureADUserWithManager = $AllAzureADUser | select *, @{ Name = "ManagerObjectId"; Expression = { Get-AzureADUserManager $_.ObjectId }}

  1. 现在,您可以在$AllAzureADUserWithManager中获得决策和更新对象所需的所有数据。如果您想使用UPN更新,您只需查找基于UPN的ObjectId

因此,假设您迭代从CSV导入的对象,其中有targetUserUPNtargetManagerUPN作为列:

代码语言:javascript
复制
$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之前的运行,如果您有大量的用户,则筛选到所需的内容。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65738104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档