SharePoint PowerShell 创建网站栏

  前言

  最近,有这么个需求,需要使用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脚本,请关注https://github.com/linyus

posted @ 2019-06-06 15:45  霖雨  阅读(652)  评论(0编辑  收藏  举报