gpt4 book ai didi

sharepoint - 通过 Powershell v3 将列添加到 SharePoint Online 2013 列表

转载 作者:行者123 更新时间:2023-12-02 03:44:13 24 4
gpt4 key购买 nike

谁能告诉我怎么做?我发现的所有示例似乎都不起作用。

我的网站是https://blah.sharepoint.com/technology我的名单叫做“心理急救”。我想添加一些文本列。

我确实通过我的 Powershell 与 SharePoint Online 建立了连接,因为我已经设法从各种命令中获得了一些结果。

谢谢。

最佳答案

如何通过 PowerShell 中的 CSOM 在 SharePoint Online 中配置字段

CSOM API 附带:

添加列表或网站栏。

下面的示例演示了如何将 GeoLocation 字段添加到 Contacts 列表中:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")

function Provision-Field([Microsoft.SharePoint.Client.ClientContext]$Context,[string]$ListTitle,[string]$FieldSchema)
{
$list = $Context.Web.Lists.GetByTitle($ListTitle)
$List.Fields.AddFieldAsXml($FieldSchema,$true,[Microsoft.SharePoint.Client.AddFieldOptions]::AddFieldToDefaultView)
$Context.Load($List)
$Context.ExecuteQuery()
}



$UserName = "username@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$URL = "https://contoso.sharepoint.com/"

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($URL)
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Password)
$Context.Credentials = $Credentials

Provision-Field $Context "Contacts" "<Field Type='Geolocation' DisplayName='Location'/>"

如何在 PowerShell 中通过 REST 在 SharePoint Online 中配置字段

端点:

http://<site url>/_api/web/fields('<field id>')

http://<site url>/_api/web/lists(guid'<list id>')/fields('<field id>')

文章Consuming the SharePoint 2013 REST API from PowerShell介绍如何将 HTTPS 请求发送到 SharePoint REST Web 服务。

使用 Invoke-RestSPO本文中的函数,以下示例演示了如何在 PowerShell 中使用 REST API 将注释字段添加到列表:

Function Add-SPOField(){

Param(
[Parameter(Mandatory=$True)]
[String]$WebUrl,

[Parameter(Mandatory=$True)]
[String]$UserName,

[Parameter(Mandatory=$False)]
[String]$Password,

[Parameter(Mandatory=$True)]
[String]$ListTitle,

[Parameter(Mandatory=$True)]
[String]$FieldTitle,

[Parameter(Mandatory=$True)]
[System.Int32]$FieldType
)


$fieldMetadata = @{
__metadata = @{'type' = 'SP.Field' };
Title = $FieldTitle;
FieldTypeKind = $FieldType;
} | ConvertTo-Json


$Url = $WebUrl + "_api/web/Lists/GetByTitle('" + $ListTitle + "')/fields"

$contextInfo = Get-SPOContextInfo $WebUrl $UserName $Password
Invoke-RestSPO $Url Post $UserName $Password $fieldMetadata $contextInfo.GetContextWebInformation.FormDigestValue
}




. ".\Invoke-RestSPO.ps1" #InInvoke-RestSPO function

$UserName = "username@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Please enter your password"
$WebUrl = "https://contoso.sharepoint.com/"


Add-SPOField -WebUrl $WebUrl -UserName $UserName -Password $Password -ListTitle "Documents" -FieldTitle "Comments" -FieldType 3

引用资料

关于sharepoint - 通过 Powershell v3 将列添加到 SharePoint Online 2013 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18132757/

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