Powershell CSOM多选项复选框

Powershell CSOM多选项复选框,powershell,sharepoint,csom,Powershell,Sharepoint,Csom,我在这方面已经到了互联网的尽头。这种资源的许多变体 我正在运行O365 Sharepoint,我有一个多复选框列表或多选择Web部件 当我查询现有条目时,数据以数组的形式返回。当我将数组发送到此字段时,它不会选中复选框,尽管字符串的值是可见的 Multi-Value {option1, option2, option3} 我不能让它工作。它甚至与我的代码格式不一样 Add-Type -Path 'C:\ServOps\com\SharepointRuntimes\Microsoft.Sh

我在这方面已经到了互联网的尽头。这种资源的许多变体

我正在运行O365 Sharepoint,我有一个多复选框列表或多选择Web部件

当我查询现有条目时,数据以数组的形式返回。当我将数组发送到此字段时,它不会选中复选框,尽管字符串的值是可见的

Multi-Value  {option1, option2, option3}

我不能让它工作。它甚至与我的代码格式不一样

Add-Type -Path 'C:\ServOps\com\SharepointRuntimes\Microsoft.SharePoint.Client.dll'
Add-Type -Path 'C:\ServOps\com\SharepointRuntimes\Microsoft.SharePoint.Client.Runtime.dll'
$url = "https://my.foo.sharepoint"

Function Write-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
$Context.ExecuteQuery()
# <context>
#    <description>The list must be fetched before ListItemCreationInformation binds to put data</description>
# </context>
$List = $Context.Web.Lists.GetByTitle($ListTitle)

$Context.Load($List)
$Context.ExecuteQuery()


# <context>
#    <description></description>
# </context>
$ListItemCreationInformation = New-Object 
Microsoft.SharePoint.Client.ListItemCreationInformation
$NewListItem = $List.AddItem($ListItemCreationInformation)
$NewListItem["Title"] = $TASK
$NewListItem["Approximate_x0020_delivery_x0020"] = $AVERAGE_DELIVERY_TIME_SLA 

$NewListItem.Update()
$Context.ExecuteQuery()
}
$context = Get-SPOContext -Url $Url -UserName $UserName -Password $Password
Write-ListItems -Context $context -ListTitle "My Sharepoint"
$context.Dispose()
添加类型-路径'C:\ServOps\com\SharepointRuntimes\Microsoft.SharePoint.Client.dll'
添加类型-路径“C:\ServOps\com\SharepointRuntimes\Microsoft.SharePoint.Client.Runtime.dll”
$url=”https://my.foo.sharepoint"
函数写入ListItems([Microsoft.SharePoint.Client.ClientContext]$Context,[String]$ListTitle){
$Context.ExecuteQuery()
# 
#必须在ListItemCreationInformation绑定到put数据之前获取列表
# 
$List=$Context.Web.Lists.GetByTitle($ListTitle)
$Context.Load($List)
$Context.ExecuteQuery()
# 
#    
# 
$ListItemCreationInformation=新对象
Microsoft.SharePoint.Client.ListItemCreationInformation
$NewListItem=$List.AddItem($ListItemCreationInformation)
$NewListItem[“Title”]=$TASK
$NewListItem[“近似交付量”]=$AVERAGE\u delivery\u TIME\u SLA
$NewListItem.Update()
$Context.ExecuteQuery()
}
$context=Get SPOContext-Url$Url-UserName$UserName-Password$Password
编写ListItems-Context$Context-ListTitle“我的Sharepoint”
$context.Dispose()

这是我的测试脚本

Add-Type -Path (Resolve-Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll")
Add-Type -Path (Resolve-Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll")

$url = "https://tenant.sharepoint.com/sites/lee/"
Function Get-SPOContext([string]$Url,[string]$UserName,$Password)
{
    write-host Get-SPOContext    
    $Context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $Context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $Password) #SecurePassword
    return $Context
}

Function Write-ListItems([Microsoft.SharePoint.Client.ClientContext]$Context, [String]$ListTitle) {
#$Context.ExecuteQuery()
# <context>
#    <description>The list must be fetched before ListItemCreationInformation binds to put data</description>
# </context>
$List = $Context.Web.Lists.GetByTitle($ListTitle)

$Context.Load($List)
$Context.ExecuteQuery()


# <context>
#    <description></description>
# </context>
$ListItemCreationInformation = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$NewListItem = $List.AddItem($ListItemCreationInformation)
$NewListItem["Title"] = "Title"
$ChoiceValue = "A","C"
$NewListItem["MyChoices"] = $ChoiceValue 

$NewListItem.Update()
$Context.ExecuteQuery()
}

$UserName = "user@tenant.onmicrosoft.com"
$Password = ConvertTo-SecureString "pw" -AsPlainText -Force  
$spoContext = Get-SPOContext -Url $Url -UserName $UserName -Password $Password

Write-ListItems -Context $spoContext -ListTitle "MyList"
$spoContext.Dispose()
Write-Host 'done'
添加类型-路径(解析路径“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”)
添加类型-Path(解析路径“C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”)
$url=”https://tenant.sharepoint.com/sites/lee/"
函数Get SPOContext([string]$Url,[string]$UserName,$Password)
{
写主机获取上下文
$Context=新对象Microsoft.SharePoint.Client.ClientContext($Url)
$Context.Credentials=新对象Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)#SecurePassword
返回$Context
}
函数写入ListItems([Microsoft.SharePoint.Client.ClientContext]$Context,[String]$ListTitle){
#$Context.ExecuteQuery()
# 
#必须在ListItemCreationInformation绑定到put数据之前获取列表
# 
$List=$Context.Web.Lists.GetByTitle($ListTitle)
$Context.Load($List)
$Context.ExecuteQuery()
# 
#    
# 
$ListItemCreationInformation=新对象Microsoft.SharePoint.Client.ListItemCreationInformation
$NewListItem=$List.AddItem($ListItemCreationInformation)
$NewListItem[“Title”]=“Title”
$ChoiceValue=“A”、“C”
$NewListItem[“MyChoices”]=$ChoiceValue
$NewListItem.Update()
$Context.ExecuteQuery()
}
$UserName=”user@tenant.onmicrosoft.com"
$Password=converttosecurestring“pw”-AsPlainText-Force
$spoContext=获取spoContext-Url$Url-UserName$UserName-Password$Password
编写ListItems-Context$spoContext-ListTitle“MyList”
$spoContext.Dispose()
写入主机“完成”

我第一件事就是尝试了这个。不幸的是,这并没有选中复选框,它只是添加了一个逗号分隔的列表。谢谢。这个脚本可以在我的测试环境中运行,你可以通过创建一个带有B C的测试字段来进行测试吗?它确实可以在添加数据的情况下运行,但是没有选中复选框。当我点击表单元素在GUI中展开(其折叠|隐藏)时,我发送的数据被清除,复选框不被选中。我正在使用O365版本