[英]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. 谢谢。
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'/>"
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
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.