gpt4 book ai didi

Powershell CSOM 多项选择复选框

转载 作者:行者123 更新时间:2023-12-01 05:50:14 32 4
gpt4 key购买 nike

我已经到了互联网的尽头。此资源的许多变体
technet set_and_get_a_multi-choice_field

我正在运行 O365 Sharepoint,我有一个多复选框列表或多选 webpart。

当我查询现有条目时,数据作为数组返回。当我向该字段发送数组时,它不会选中复选框,但字符串的值是可见的。

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

最佳答案

这是我的测试脚本。

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'

关于Powershell CSOM 多项选择复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55425512/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com