Чекбокс Powershell CSOM Mutli-Choice - PullRequest
4 голосов
/ 30 марта 2019

Я достиг конца Интернета в этом. Много вариаций этого ресурса technet set_and_get_a_multi-choice_field

Я использую O365 Sharepoint, и у меня есть список с несколькими флажками или несколько веб-частей.

Когда я запрашиваю существующие записи, данные возвращаются в виде массива. Когда я отправляю массив в это поле, он не устанавливает флажки, хотя значения строки видны.

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 голосов
/ 01 апреля 2019

Вот мой тестовый скрипт.

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'
...