首页 > 其他专区 > SharePoint >

SharePoint PowerShell 创建网站栏

SharePoint 2021-09-22 09:41:59

最近,有这么个需求,需要使用PowerShell为网站集创建网站栏,好吧,直接看代码吧。
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$webUrl = "HTTP://SITEURL"
$listname = "LISTNAME"
$fieldname = "FIELDNAME"
$IsRequired = $False
$FieldType = [Microsoft.SharePoint.SPFieldType]::Text

$site = Get-SPSite $webUrl
$Web = $site.OpenWeb()
$list = $web.Lists.TryGetList($listname)
$field = $list.Fields[$fieldname];

if($field -eq $null)
{
$list.Fields.Add($fieldname,$FieldType,$IsRequired)
$list.Update()
Write-Host $fieldname "is created"
}
else
{
Write-Host $fieldname "is already exist"
}

复制代码

  结束语

  其实,整个代码逻辑和SharePoint其他对象很相似,只要掌握PowerShell和其他对象一些简单的语法区别即可。


标签: PowerShell创建网站栏

office教程网 Copyright © 2016-2020 https://www.office9.cn. Some Rights Reserved.