Create/Delete list via powershell
来源:互联网 发布:帝国cms邀请码 编辑:程序博客网 时间:2024/06/15 22:00
1. Create list by custom list template
#***************************************************************************************************************
# Create a list by the custom list template
# $spSiteUrl: The site url
# $spTemplate: The name of list template
# $spListName: The name of the list
# $spDescription: Th edescription about the new list
# $quickLaunchView: Show the list in quicklaunch true or false
# Example: CreateCustomList http://localhost "MyTemplate" "MyNewList2" "This is my list" "true"
#***************************************************************************************************************
function CreateCustomList($spSiteUrl, $spTemplate, $spListName, $spDescription, $quickLaunchView) { $spSite = Get-SPSite $spSiteUrl.trim() $spWeb = $spSite.RootWeb $spTemplate = $spTemplate.trim() $spListName = $spListName.trim() $quickLaunchView = $quickLaunchView.trim() # Check the name is null or not if($spTemplate -eq $null -or $spListName -eq $null -or $quickLaunchView -eq $null) { write-host "The parameter is null" return } try{ # Get all the custom template $listTemplates = $spSite.GetCustomListTemplates($spWeb); # check the list name is right or not if(!($spListName -match "\w+")) { write-host "The list name is wrong" return } # Check list is exist or not foreach($list in $spWeb.Lists) { if($list.Tostring() -eq $spListName) { write-host "The list named $list is existing" return } } # check the template name is right or not if(!($spTemplate -match "\w+")) { write-host "The template name is wrong" return } # Check the $quickLaunchView is right or not if($quickLaunchView -ne "true" -and $quickLaunchView -ne "false") { write-host "The $quickLaunchView is not right choice" return } # check the template name is existing or not foreach($template in $listTemplates) { if($template.name -eq $spTemplate) { # Create the list via the template name $spWeb.Lists.Add($spListName, $spDescription, $listTemplates[$spTemplate]) $list = $spWeb.Lists[$spListName] # Make the list view in OnQuickLaunch if($quickLaunchView -eq "true") { $list.OnQuickLaunch = "True" $list.Update() } if($quickLaunchView -eq "false") { $list.OnQuickLaunch = "False" $list.Update() } write-host "Create the list success" return } } write-host "The template named $spTemplate is not existing" return } catch{ write-host "(ERROR : "$_.Exception.Message")" throw } finally{ $spWeb.Dispose() $spSite.Dispose() } }
2. Delete the list by name
#***************************************************************************************************************
# Delete the list by name
# $spSiteUrl: The site url
# $spTemplate: The name of list template
# $spListName: The name of the list
# $spDescription: Th edescription about the new list
# $quickLaunchView: Show the list in quicklaunch true or false
# Example : DeleteListByName http://localhost "MyNewList2"
#***************************************************************************************************************
function DeleteListByName($siteUrl, $spListName) { $spSite = Get-SPSite -identity $siteUrl.trim() $spWeb = $spSite.RootWeb try{ $spListName = $spListName.trim() # check the list name is right or not if(!($spListName -match "\w+")) { write-host "The list name is wrong" return } # Check list is exist or not foreach($list in $spWeb.Lists) { if($list.Tostring() -eq $spListName) { $list.Delete() write-host "Delete the list named $spListName success" return } } write-host "The list name $spListName is not existing" return } catch{ write-host "(ERROR : "$_.Exception.Message")" throw } finally{ DisposeWebObject($spWeb) } }
- Create/Delete list via powershell
- Add/Delete ContentType in list via powershell
- Restore list by name from recyclebin via powershell
- To create a sharepoint list by using powershell
- Create a custom list and delete a list
- Accesing Metro via PowerShell-Appx Powershell Cmdlets
- Create MOS via ffmpeg
- SharePoint PowerShell Create Site
- Create subtask in task list via client javascript in sharepoint 2013
- Via composer create Laravel project
- list delete
- List Delete
- create & delete svn service
- Create dump via taskmgr in XP
- how to create workflow diagram via vosio
- Manual database creating via "create database" statement
- Group list data via linq
- 【代码积累】InsertionSort via list
- 隔行变色
- MyEclipse 内存溢出解决方法
- window下变更MySQL的数据目录
- 负载均衡总结(百科)
- 今天的积累
- Create/Delete list via powershell
- Myeclipse Tomcat Web项目转换为Maven3
- Android4.1输入子系统框架介绍和性能分析
- UINavigationController的popViewControllerAnimated问题
- Debian/Ubuntu 时区和自动校时设置
- mysql的基本使用命令
- c# 控制台程序设置字体颜色
- SolrCloud Performance 测试(query-fetch)
- GUI系统之SurfaceFlinger(5)BufferQueue内部原理