Powershell CSOM多种选择复选框

时间:2019-03-29 21:09:46

标签: powershell sharepoint csom

我已经达到了这个目的。该资源的许多变化 technet set_and_get_a_multi-choice_field

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

查询现有条目时,数据以数组形式返回。当我向该字段发送数组时,尽管该字符串的值是可见的,但它并未选中复选框。

Multi-Value  {option1, option2, option3}

multi-select

我无法使用它。甚至与我的代码使用的格式都不一样

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()

1 个答案:

答案 0 :(得分:0)

这是我的测试脚本。

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'