[英]Error passing a comma separated String to Add-UnifiedGroupLinks resuling in a “Couldn't find object” error
I am trying to bulk-load an Office 365 Group using Add-UnifiedGroupLinks which works if only passing one value as a string but the command supports a comma separated list. 我正在尝试使用Add-UnifiedGroupLinks批量加载Office 365组,如果只将一个值作为字符串传递但命令支持以逗号分隔的列表,则可以正常工作。 However, when passing it a comma separated string it returns "Couldn't find object "user1@domain.com,user2@domain.com"
但是,当传递逗号分隔的字符串时,它返回“找不到对象”user1 @ domain.com,user2 @ domain.com“
I can get it to work by running only one user at a time but it is MUCH slower and based on the large number of users doesn't really suite my needs. 我可以通过一次只运行一个用户来实现它,但速度慢得多,并且基于大量用户并不能真正满足我的需求。 I can take the string that I build and copy and paste from that and run the same line of code manually and it works without issue.
我可以使用我构建的字符串并从中复制和粘贴,并手动运行相同的代码行,它可以正常工作。 I also tried with only 3 or 5 users at a time but same issue.
我也尝试过一次只有3或5个用户,但同样的问题。
$sb = New-Object System.Text.StringBuilder
$i = 1
Import-CSV "myCSV.csv" | ForEach-Object {
[void]$sb.Append($_.UserPrincipalName + ',')
if($i -eq 20) {
$sb.Length--
Add-UnifiedGroupLinks –Identity "MyGroupName" –LinkType Members –Links $sb.ToString()
Write-Host $sb.ToString()
$sb.Clear()
$i = 1
}
Else {$i++}
}
Note: I have additional code to handle the remainder after the loop runs but not relevant to the issue at hand. 注意:我有额外的代码来处理循环运行后的余数,但与手头的问题无关。
It returns Couldn't find object "user1@domain.com,user2@domain.com"
. 它返回
Couldn't find object "user1@domain.com,user2@domain.com"
。 However if I manually run this line, it works: 但是,如果我手动运行此行,它的工作原理如下:
Add-UnifiedGroupLinks –Identity "MyGroupName" –LinkType Members –Links user1@domain.com,user2@domain.com
Or if I do one at a time it works: 或者,如果我一次做一个它的工作原理:
Import-CSV "myCSV.csv" | ForEach-Object {
Add-UnifiedGroupLinks –Identity "MyGroupName" –LinkType Members –Links $_.UserPrincipalName
}
but performance is awful with the last option when doing over 20K users it is averaging about 400 an hour (one every 9 seconds or so). 但是当使用超过20K的用户时,最后一个选项的性能非常糟糕,平均每小时约400个(每9秒一个左右)。
Instead of using String builder, I should have used an Array of Strings and passed that in: 我应该使用一个字符串数组并将其传递给:而不是使用字符串构建器:
$strArr = New-Object System.Collections.ArrayList
Import-CSV "myCSV.csv" | ForEach-Object {
$strArr.Add($_.UserPrincipalName) > $null
if($strArr.Count -eq 100) {
Add-UnifiedGroupLinks –Identity "MyGroupName" –LinkType Members –Links $strArr
$strArr.Clear()
}
}
Add-UnifiedGroupLinks –Identity "MyGroupName" –LinkType Members –Links $strArr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.