Add/Delete ContentType in list via powershell
来源:互联网 发布:php 正则函数 编辑:程序博客网 时间:2024/05/22 10:29
1. Add contenttype to the list
#########################################################################
# $siteUrl : The storeportal site. http://loacalhost #
# $listName : The name of the list. "Store Requests" #
# $contentTypeName: The contenttype name "Document" #
# Example : AddContentTypeToList "http://loacalhost" "Shared Documents" "Document" #
#########################################################################
# Import the Microsoft.SharePoint.PowerShellif ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ){ Add-PSSnapin Microsoft.SharePoint.PowerShell}function AddContentTypeToList($siteUrl, $listName, $contentTypeName){ $site = Get-SPSite -identity $siteUrl $spWeb = Get-SPWeb -identity $siteUrl $contentTypes = $site.rootweb.ContentTypes try{ # Check list is exist or not foreach($list in $spWeb.Lists) { if($list.Tostring() -eq $listName) { write-host "The list named $list is existing " # Check contentType is existing in the site if(($contentTypes|where {$_.Name -eq $contentTypeName}) -eq $null) { write-host "The contentType is not existing in the site" return } # Check contentType is exist or not in the list foreach($listCT in $list.ContentTypes|where {$_.Name -eq $contentTypeName}) { write-host "The contentType $contentTypeName is exiting in the list" return } $contentType = $spWeb.ContentTypes[$contentTypeName] $list.ContentTypes.Add($contentType) $list.Update() write-host "Add contentType success" return } } write-host "The list named $list is not existing " } catch{ write-host "(ERROR : "$_.Exception.Message")" throw } finally{ $spWeb.Dispose() } }
2. Delete the contenttype in list
#########################################################################
# $siteUrl : The storeportal site. http://loacalhost #
# $listName : The name of the list. "Store Requests" #
# $contentTypeName: The contenttype name "Document" #
# Example : DeleteContentType http://localhost "Shared Documents" "Document Set" #
#########################################################################
# Import the Microsoft.SharePoint.PowerShellif ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ){ Add-PSSnapin Microsoft.SharePoint.PowerShell}function DeleteContentType($siteUrl, $listName, $contentTypeName){ $spSite = Get-SPSite -identity $siteUrl $spWeb = Get-SPWeb -identity $siteUrl $contentTypes = $spSite.rootweb.ContentTypes try{ # Check list is exist or not foreach($list in $spWeb.Lists) { if($list.Tostring() -eq $listName) { write-host "The list named $list is existing " # Check contentType is existing in the site if(($contentTypes|where {$_.Name -eq $contentTypeName}) -eq $null) { write-host "The contentType is not existing in the site" return } # Check contentType is exist or not in the list if(($list.ContentTypes|where {$_.Name -eq $contentTypeName}) -eq $null) { write-host "The contentType $contentTypeName is not exiting in the list" return } else { $contentType = $list.ContentTypes[$contentTypeName] $list.ContentTypes.Delete($contentType.Id) $list.Update() write-host "Delete contentType success" } return } } write-host "The list named $list is not existing " } catch{ write-host "(ERROR : "$_.Exception.Message")" throw } finally{ $spWeb.Dispose() $spSite.Dispose() } }
- Add/Delete ContentType in list via powershell
- Create/Delete list via powershell
- Add/Remove listview web part in publish site via powershell
- Add Script Editor and Content Editor Web Part via powershell
- Add Product Images via CSV in Magento
- Add new disk via LVM in linux
- Restore list by name from recyclebin via powershell
- How to add Snap-in (扩展Powershell)
- 【二叉树】二分查找树,节点删除【Add to List 450. Delete Node in a BST】
- add source.list in ubuntu
- Add, Search, Delete Node in BST.
- Accesing Metro via PowerShell-Appx Powershell Cmdlets
- leetcode: Delete Node in a Linked List
- LeetCode Delete Node in a Linked List
- Delete Node in a Linked List
- 【leetcode】Delete Node in a Linked List
- Delete Node in a Linked List
- Delete Node in a Linked List
- SpringMVC 接收表单数据的方式
- 基于SDL的mp3播放器
- SpringMVC注解说明
- 中断子系统分析(一)
- NSValue包装对象指针,CGRect结构体等
- Add/Delete ContentType in list via powershell
- IOS之触摸事件和手势
- SpringMVC 配置
- AndroidManifest.xml中ShortCut[Broadcast方式]
- SecureCRT按退格键出现^H问题
- javascript setTimeout参数传变量
- POJ 1475 Pushing Boxes 搜索- 两重BFS
- PHP静态变量、成员、方法
- ACE 主动对象模式的按部就班的实现方法