我想在SharePoint列表的多选取器person字段中添加多个用户。我尝试了下面的代码,但总是得到一个错误:
Microsoft.SharePoint.SPFieldUserValueCollection:
新对象:找不到类型,请验证是否加载了包含此类型的程序集。
有人能帮我解决这个问题吗?
$ClientContext = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Securedpw = ConvertTo-SecureString $Password -AsPlainText -Force
$ClientContext.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Securedpw)
$web = $ClientContext.Web
$list= $web.lists.GetByTitle($listName)
$ClientContext.Load($list)
$ClientContext.ExecuteQuery()
$ListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ListItem= $list.AddItem($ListItemCreationInformation)
$UserAccounts="domain\arzoo; domain\ashwin"
$UserAccountsColl = $UserAccounts -split ';'
$UserCollection = new-object Microsoft.SharePoint.SPFieldUserValueCollection
foreach($UserAccount in $UserAccountsColl)
{
#Get the User
$User=$web.EnsureUser($UserAccount)
#Add to collection
$UserFieldValue = new-object Microsoft.SharePoint.SPFieldUserValue($Web, $User.ID, $User.LoginName)
$UserCollection.Add($UserFieldValue)
}
#update the Multiple value Person or Group field
$ListItem[$FieldName] = $UserCollection
$ListItem.Update()
发布于 2019-04-12 09:13:26
您可以很容易地使用PnP Powershell来实现这一点。
#region Variables
$Username = "lee@tenant.onmicrosoft.com"
$Password = "pw"
$siteURL = "https://tenant.sharepoint.com/sites/lee"
#endregion Variables
#region Credentials
[SecureString]$SecurePass = ConvertTo-SecureString $Password -AsPlainText -Force
[System.Management.Automation.PSCredential]$PSCredentials = New-Object System.Management.Automation.PSCredential($Username, $SecurePass)
#endregion Credentials
Connect-PnPOnline -Url $siteURL -Credentials $PSCredentials
$users = "user1@tenant.onmicrosoft.com", "user2@tenant.onmicrosoft.com"
Set-PnPListItem -List "MyList" -Identity 9 -Values @{"User"=$users}
https://stackoverflow.com/questions/55634506
复制相似问题