简体   繁体   English

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

[英]Add column to SharePoint Online 2013 list via Powershell v3

Can anybody tell me how to do this? 谁能告诉我怎么做? None of the examples I have found seem to work. 我找到的所有例子似乎都没有用。

My site is https://blah.sharepoint.com/technology and my list is called 'pfa'. 我的网站是https://blah.sharepoint.com/technology ,我的名单叫做'pfa'。 I want to add some text columns. 我想添加一些文本列。

I DO have connectivity with SharePoint Online via my Powershell, as I have managed to get some results back from various commands. 我通过我的Powershell与SharePoint Online建立了连接,因为我已经设法从各种命令中获得了一些结果。

Thanks. 谢谢。

How to provision field in SharePoint Online via CSOM in PowerShell 如何通过PowerShell中的CSOM在SharePoint Online中设置字段

CSOM API comes with: CSOM API附带:

to add a list or site column. 添加列表或站点列。

The example below demonstrates how to add GeoLocation field into Contacts List: 以下示例演示了如何将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'/>"

How to provision field in SharePoint Online via REST in PowerShell 如何在PowerShell中通过REST在SharePoint Online中设置字段

Endpoints: 终点:

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

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

The article Consuming the SharePoint 2013 REST API from PowerShell describes how send HTTPS requests to SharePoint REST web services. 从PowerShell使用SharePoint 2013 REST API的文章介绍了如何向SharePoint REST Web服务发送HTTPS请求。

Using the Invoke-RestSPO function from the article, the following example demonstrates how to add Note field to List using REST API in PowerShell: 使用本文中的Invoke-RestSPO函数,以下示例演示了如何使用PowerShell中的REST API将List字段添加到List:

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

References 参考

Here is someone who created a list with the CSOM through PowerShell with SharePoint Oneline http://www.hartsteve.com/2013/06/sharepoint-online-powershell/ 以下是通过PowerShell与SharePoint Oneline一起使用CSOM创建列表的人http://www.hartsteve.com/2013/06/sharepoint-online-powershell/

The PowerShell stuff for SharePoint online is limited to some basic admin tasks only. SharePoint Online的PowerShell内容仅限于一些基本的管理任务。 When you used the CSOM in PowerShell, you can do a lot more. 在PowerShell中使用CSOM时,您可以做更多事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过Powershell将照片库添加到Sharepoint 2013 - Add Photo library to Sharepoint 2013 via powershell 如何通过powershell列出sharepoint在线目录中的文件 - How to list the files in a sharepoint online directory via powershell Sharepoint Online(2013)列格式不起作用 - Sharepoint Online (2013) Column Formatting Not Working 如何通过在另一台服务器上为Sharepoint 2013和Sharepoint Online运行的脚本中的REST API通过REST API更新SharePoint列表? - How do I update a SharePoint list via REST API in a script ran on another server for Sharepoint 2013 an also Sharepoint Online? 使用VS 2013在Sharepoint Online 2013中创建自定义列表 - Create Custom List in Sharepoint Online 2013 using VS 2013 SharePoint 2013 /在线-使用共享点组中的域组到人员列 - SharePoint 2013/Online - Using a Domain group in a sharepoint group to a person column SharePoint 2013-添加到列表但没有查看 - SharePoint 2013 - Add to list but no viewing 使用 Sharepoint Online 2013 从 Sharepoint Webservice 访问列表 - Accessing list from Sharepoint Webservice with Sharepoint Online 2013 向SharePoint Online网站PowerShell添加替代语言 - Add alternative language to SharePoint Online Sites PowerShell Powershell Sharepoint Online - 将内容类型添加到列表 - Powershell Sharepoint Online - Adding a content type to a list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM