简体   繁体   English

将逗号分隔的String传递给Add-UnifiedGroupLinks时出错导致“无法找到对象”错误

[英]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.

相关问题 RoR:使用字符串primary_key创建对象(关联错误:找不到ID = 0的Object_Id) - RoR: Creating an Object with string primary_key (associated error: Couldn't find Object_Id with ID=0) 逗号分隔字符串的对象 - Object to comma separated string Excel-从逗号分隔的列表中查找确切的字符串 - Excel - find exact string from comma separated list 查找用逗号分隔的字符串出现的次数并输出该字符串 - Find the number of occurrences of strings separated by comma and output the string 逗号使用jquery或javascript将Key和Value字符串分隔为Object - Comma Separated Key and Value string to Object using jquery or javascript 如何将逗号和分号分隔的字符串拆分为JSON对象 - How to split comma and semicolon separated string into a JSON object Python中有效的方法是将元素添加到以逗号分隔的字符串中 - Efficient way in Python to add an element to a comma-separated string T-SQL如何将逗号分隔的数字字符串转换为整数 - T-SQL How to convert comma separated string of numbers to integer 如何在主字符串中找到多个逗号分隔的字符串 - how to find multiple comma separated string in main string Object class 无法转换为字符串 Laravel 5 - Object class couldn't be converted to string Laravel 5
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM