按EmployeeID更新多个用户ADGroup

问题描述 投票:0回答:1

我正在尝试通过Employee为CSV文件中的多个用户更新AzureADGroupMember。

这是我得到了帮助,但希望通过UPN而不是EmployeeID进行更新。这是UPN更新ADGroupMember的成功代码。

$users = Import-csv "C:\Temp\testgroup2.csv" 

$users | ForEach-Object{
Add-AzureADGroupMember -ObjectId 599992-xxxxxxxxxx-699999e9e - 
RefObjectId (Get-AzureADUser -ObjectId $_.UPN).ObjectId
}

这是我通过CSV中的EmployeeID更改UPN以更新的代码。

$users = Import-csv "C:\Temp\testgroup2.csv" 

$users | ForEach-Object{
Add-AzureADGroupMember -ObjectId 599992-xxxxxxx-6ee9999e - 
RefObjectId (Get-AzureADUser -ObjectId $_.EmployeeID).ObjectId
}

这是我尝试按EmployeeID更新时收到的错误消息。

Get-AzureADUser : Error occurred while executing GetUser Code: 
Request_ResourceNotFound Message: Resource '18616' does not exist or one 
of its queried reference- property objects are not present. 

这就是我用来验证员工在Azure中实际拥有EmployeeID的原因。

Get-AzureADUser -ObjectID [email protected] | Select-Object *

任何想法为什么它读取即使我已经验证了Azure中不存在employeeID?

谢谢,

更新:添加我的csv设置的屏幕截图,我只有员工ID:CSV Setup

更新2:我在powershell中运行的脚本的屏幕截图:Script in PS

azure azure-active-directory azure-powershell azure-ad-powershell-v2
1个回答
0
投票

employeeIdObjectId不同,因此您无法将employeeId传递给ObjectId属性。

尝试下面的脚本,它在我身边工作正常。

$users = Import-csv "C:\Users\joyw\Desktop\testgroup.csv" 
foreach($user in $users){
    $refobjectid = (Get-AzureADUser | Where-Object {$_.ExtensionProperty.employeeId -eq $user.employeeId}).ObjectId
    Add-AzureADGroupMember -ObjectId 9d42d3ea-xxxxxxxx-c31428b600ad -RefObjectId $refobjectid
}

我的.csv文件:

UPN,Role,employeeId
[email protected],role1,12345
[email protected],role2,123

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.