powershell 此脚本在不移动数据的情况下复制列表。它将列表保存为模板,使用模板创建列表,然后删除t
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 此脚本在不移动数据的情况下复制列表。它将列表保存为模板,使用模板创建列表,然后删除t相关的知识,希望对你有一定的参考价值。
#this ifxes the issues with the URL and list title
write-host "This script copies a list within the same site collection and same web" -foregroundcolor white -backgroundcolor blue
$sourceSite = "http://spsvde001/tools/cats"
$sourceListName = "CATS 2014 Archive"
$destinationListName = "CatsArchive2015"
$destinationListDescription = "CATS Archive 2015"
$destinationListTitle = "CATS 2015 Archive"
$site = New-Object Microsoft.SharePoint.SPSite($sourceSite)
$web = $site.OpenWeb()
$sourceList = $web.Lists[$sourceListName]
$templateName = $sourceList.Title
$templateFileName = $sourceList.Title
write-host "Saving the $templateFileName template" -foregroundcolor white -backgroundcolor green
$sourceList.SaveAsTemplate($templateFileName, $templateName, $sourceList.Description, $false)
$listTemplate = $site.GetCustomListTemplates($web)[$templateName]
$destWeb = $site.OpenWeb()
write-host "Adding the list $destinationListName from the template" -foregroundcolor white -backgroundcolor green
$list = $destWeb.Lists.Add($destinationListName, $destinationListDescription, $listTemplate)
$destWeb.Update()
#Change the list title
write-host "Changing the list name to $destinationListTitle" -foregroundcolor white -backgroundcolor green
$destList = $destWeb.Lists[$destinationListName]
$destList.Title = $destinationListTitle
$destList.Update()
#remove the list template
$listTemplates = $site.RootWeb.Lists["List Template Gallery"]
$listTemplateItems = $listTemplates.Items
write-host "Deleting the template" -foregroundcolor white -backgroundcolor green
foreach($listTemplateItem in $listTemplateItems)
{
if($listTemplate.Name.Equals($listTemplateItem["Title"]))
{
$listTemplateItem.Delete()
break
}
}
write-host "The List is copied without data" -foregroundcolor white -backgroundcolor green
$web.Dispose()
$destWeb.Dispose()
$site.Dispose()
write-host "This script copies a list within the same site collection and same web" -foregroundcolor white -backgroundcolor blue
$sourceSite = "http://spsvde001/tools/cats"
$sourceListName = "CATS 2014 Archive"
$destinationListName = "CATS 2016 Archive"
$destinationListDescription = "CATS Archive 2016"
$site = New-Object Microsoft.SharePoint.SPSite($sourceSite)
$web = $site.OpenWeb()
$sourceList = $web.Lists[$sourceListName]
$templateName = $sourceList.Title
$templateFileName = $sourceList.Title
write-host "Saving the $templateFileName template" -foregroundcolor white -backgroundcolor green
$sourceList.SaveAsTemplate($templateFileName, $templateName, $sourceList.Description, $false)
$listTemplate = $site.GetCustomListTemplates($web)[$templateName]
$destWeb = $site.OpenWeb()
write-host "Adding the list $destinationListName from the template" -foregroundcolor white -backgroundcolor green
$list = $destWeb.Lists.Add($destinationListName, $destinationListDescription, $listTemplate)
$destWeb.Update()
$listTemplates = $site.RootWeb.Lists["List Template Gallery"]
$listTemplateItems = $listTemplates.Items
write-host "Deleting the template" -foregroundcolor white -backgroundcolor green
foreach($listTemplateItem in $listTemplateItems)
{
if($listTemplate.Name.Equals($listTemplateItem["Title"]))
{
$listTemplateItem.Delete()
break
}
}
write-host "The List is copied without data" -foregroundcolor white -backgroundcolor green
$web.Dispose()
$destWeb.Dispose()
$site.Dispose()
以上是关于powershell 此脚本在不移动数据的情况下复制列表。它将列表保存为模板,使用模板创建列表,然后删除t的主要内容,如果未能解决你的问题,请参考以下文章
在不提示的情况下在 Powershell 中获取当前用户的凭据对象
如何在不大幅增加其大小的情况下在 PowerShell 中保存文本文件?
powershell 用新鲜的空邮箱开始新的一年。此脚本将电子邮件从日期范围内的收件箱(默认文件夹)移动到另一个文件夹。