SHarePoint PowerShell将列表视图复制到其他站点/列表 [英] SHarePoint PowerShell copy list views to other site(s)/list(s)

查看:67
本文介绍了SHarePoint PowerShell将列表视图复制到其他站点/列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此处提供/注明的代码

https://gallery.technet.microsoft.com/Script-to-copy-SharePoint-9efff249

复制所有列表视图(包括更新/调整时间)从"模板"列表到从该原始列表创建的目标列表。


随着时间的推移,我们需要对源列表中的内容类型或站点列进行小的更改,这些更改会被推送到从源模板创建的所有站点/列表中这很好用。


但我们想要对列表视图进行的任何更改都不能全局推送,并且通常需要对多个子网站进行手动列表视图编辑。

上面提到的PowerShell代码在复制视图时工作得很好,但是没有将"默认视图"设置和聚合状态/设置(Count,SUM,MAX等)复制到目标视图......和我正在努力弄清楚为什么我不能
似乎让它工作。

I am attempting to use the code as provided/noted here
https://gallery.technet.microsoft.com/Script-to-copy-SharePoint-9efff249
to copy all list views(with their updates/adjustments over time) from a 'template' list to destination list(s) that were created from that original list.
Over time, as we need to maybe make small changes to the Content Types or Site Columns in that source list, these changes get pushed out to all sites/lists created from the source template and this works fine.
But any changes we'd like to make to Lists views cannot be pushed globally and would normally require manual List View edits to multitudes of subsites.
The above noted PowerShell code works fine enough as-is in copying the Views, but does not copy the 'Default View' setting and Aggregation status/settings(Count, SUM, MAX, etc.) into the destination Views...and I'm struggling to figure out why I can't seem to get it to work.

    <#
.SYNOPSIS
   Copy-SPListViews
.DESCRIPTION
   Script to copy all public views and current user private views from one SharePoint list/library to another.

   The source and the destination lists can be in the same web or in different site collections/webs.

   Properties that will be copied: Title , View Query, Is Paged, Is Personal View , Row Limit, Is Default View, View Fields, View Type

   If there is a view with same name in the source and destination list it will not be overwritten, a new view with the parameters of the source will be created.

   Tested on: SharePoint 2010, SharePoint 2013, SharePoint 2016 RC

   Author: Ivan Yankulov [ Senior SharePoint Engineer @ bluesource Information Limited ]
   Contact: http://spyankulov.blogspot.com
   About this script: http://spyankulov.blogspot.com/2016/02/copy-list-views-in-sharepoint-online-powershell.html
   
.PARAMETER SourceWebUrl
   The URL of the source web
.PARAMETER DestinationWebUrl
   The URL of the destination web
.PARAMETER SourceListTitle
   The source list Name/Title
.PARAMETER DestinationListTitle
   The destination list Name/Title
.EXAMPLE
   .\Copy-SPListViews.ps1 -SourceWebUrl "https://portal.contoso.com/sites/teamsite/" -DestinationWebUrl "https://portal.contoso.com/hr" -SourceListTitle "Team Documents" -DestinationListTitle "HR Documents"
   
 Description
 -----------
 This will copy the views from the source list "Team Documents" to destination list "HR Documents"

 .INPUTS
 System.String[]
 .OUTPUTS
 .LINK
http://spyankulov.blogspot.com
http://spyankulov.blogspot.com/2016/02/copy-list-views-in-sharepoint-online-powershell.html
#>

	[CmdletBinding()]
    Param(
    [parameter(Mandatory=$true)]
	[string]$SourceWebUrl,
    [parameter(Mandatory=$true)]
	[string]$DestinationWebUrl,
    [parameter(Mandatory=$true)]
	[string]$SourceListTitle,
    [parameter(Mandatory=$true)]
	[string]$DestinationListTitle
    )
BEGIN{
    Add-PSSnapin *SH* -ErrorAction SilentlyContinue
    $sWeb = Get-SPWeb -Identity $SourceWebUrl
    $sourceList = $sWeb.Lists[$SourceListTitle]

	$dWeb = Get-SPWeb -Identity $DestinationWebUrl
    $destinationList = $dWeb.Lists[$DestinationListTitle]

	$sourceViews = $sourceList.Views
	$destinationViews = $destinationList.Views
}
PROCESS{
	ForEach($sourceView in ($sourceViews | Where {$_.Hidden -eq $false})){
		Write-Host "Creating View `"$($sourceView.Title)`"" -ForegroundColor Green
		$title = $sourceView.Title

		$viewFlds = New-Object System.Collections.Specialized.StringCollection
		
		ForEach ($vf in $sourceView.ViewFields){
			$viewFlds.Add($vf.ToString()) | Out-Null
		}
		$vQuery = $sourceView.Query
		$vRowLimit = $sourceView.RowLimit
		$vPaged = $sourceView.Paged
		$vDF = $sourceView.DefaultView
		$vType = $sourceView.Type
		$vPersonal = $sourceView.PersonalView
		
		$destinationList.Views.Add($title,$viewFlds,$vQuery,$vRowLimit,$vPaged,$vDF,$vType,$vPersonal) | Out-Null
		
	}
	$destinationList.Update()
}

而且,我很乐意玩在代码下面,在"$ destinationList.Views.Add"周围插入必要的部分。在上面的代码中,它可以自行运行:

and, I'd ben playing with the below code, inserting necessary parts right around the "$destinationList.Views.Add" in above code which works fine on it's own:

$web = "https://somesite/site/list"
 $spsite = [Microsoft.SharePoint.SPSite]($web)
 $web = $spsite.OpenWeb()
 $view = $web.GetViewFromURL("Lists/List/All%20Items.aspx")
 $aggregations = "<FieldRef Name='LinkTitle' Type='COUNT'/>"
 $view.Aggregations = $aggregations
 $view.AggregationsStatus = "On"
 $view.Update()

基本上,我们要复制视图(使用默认视图,聚合和聚合状态设置)从源"模板"网站中的特定列表,到另一个网站的子网站中的特定匹配列表。这些目的地列表基本上是
,直接从他们的源列表中创建,作为网站模板包的一部分。 

可能任何人都可以在正确的方向上轻推我部分代码?

Basically, we'd like to copy views(WITH the Default View, Aggregation and AggregationStatus settings) from specific lists in a source 'template' site, to specific matching lists in another site's subsites. These destination lists were basically created directly from their source lists as part of a Site Template package. 
Might anybody be able to nudge me in the right direction right around the below portion of the code?

ForEach ($vf in $sourceView.ViewFields){
			$viewFlds.Add($vf.ToString()) | Out-Null
		}
		$vQuery = $sourceView.Query
		$vRowLimit = $sourceView.RowLimit
		$vPaged = $sourceView.Paged
		$vDF = $sourceView.DefaultView
		$vType = $sourceView.Type
		$vPersonal = $sourceView.PersonalView
		
		$destinationList.Views.Add($title,$viewFlds,$vQuery,$vRowLimit,$vPaged,$vDF,$vType,$vPersonal) | Out-Null
		
	}
	$destinationList.Update()

推荐答案

您好,

我们可以替换以下代码行

We can replace the following line of code


destinationList.Views.Add(
destinationList.Views.Add(


title,


这篇关于SHarePoint PowerShell将列表视图复制到其他站点/列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆