我正尝试为员工更新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
}
这是我更改UPN以通过CSV中的EmployeeID更新的代码。
$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 Xxxxx@hxxxxxx.com | Select-Object *
有什么主意,即使我已经验证过,为什么还要读取到employeeID在Azure中不存在?
谢谢
更新:添加我的csv设置的屏幕截图,我那里只有Employee ID: CSV Setup
更新2:我在Powershell中运行的脚本的屏幕截图:Script in PS
答案 0 :(得分:0)
import glob
# Get all txt files in the directory:
paths = glob.glob('/my/path/*.txt')
for path in paths:
# Do something with the path
processPath(path)
与employeeId
不同,因此您无法传递employeeId
到ObjectId属性。
尝试以下脚本,对我而言效果很好。
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