如何生成报告来枚举出整个sharepoint环境中的每个页面所使用的所有webpart
2014-08-17 01:54
477 查看
背景
我的公司的SharePoint环境中购买了大量的第三方webpart,比如Quick Apps, Telerik RadEditor, Nintex Workflow等等。。这样做的好处就是成本相对于雇人开发自定义webpart来的性价比更高,因为找来开发团队可能价格很贵而且开发周期结束之后的长期维护可能会很麻烦。而通过购买第三方公司制作的webpart,不但实现了功能,还能得到长期的技术支持,这样在遇到灾难恢复或者SharePoint升级到新版本的时候,你的维护升级成本相对于雇人写代码来说就会显得相当的便宜。当然买的webpart多了就会有问题,因为你不知道哪些用的多,哪些用的少,如果不能掌握他们被使用的具体数量,我们就无法决策说那些webpart在合同到期后应该要需要继续使用,而哪些则因为使用的范围太小应该被弃用。
于是我们写了一个不算很短但并不复杂的powershell脚本来找出每个页面所使用的webpart并导出结果,再将结果放到Excel中做出图表方便大家理解。
代码
我们直接看代码。param([switch]$help) [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing") function GetHelp() { $HelpText = "This script will list out the webparts type along with the names in publishing pages in all site ." $HelpText } function GetWebpartInfoInOnePage($page) { $manager = $web.GetLimitedWebPartManager($page, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) $webCollection = $manager.WebParts if ($webCollection.Count -ne 0) { $pageUrl=$web.Url+'/'+$page for ($i = 0; $i -lt $webCollection.Count; $i++) { $webpartType = $webCollection[$i].GetType().Name if ($webpartType -eq "ErrorWebPart") { $repreWebpartType=$webCollection[$i].RepresentedWebPartType.Name $realType=$repreWebpartType.SubString($repreWebpartType.LastIndexOfAny(".") + 1) write-host($i + 1).ToString() " " $pageUrl " " $realType " " $webCollection[$i].Title } else { write-host($i + 1).ToString() " " $pageUrl " " $webCollection[$i].GetType().Name " " $webCollection[$i].Title } } } } function RahulPublishingPageWebParts() { write-host "This script will enlist the webparts used in all publishing pages " $allWebapplications = Get-SPWebApplication foreach($webapp in $allWebapplications) { foreach($site in $webapp.Sites) { foreach($web in $site.AllWebs) { $pagesList=$web.Lists["Pages"] if($pagesList -ne $null) { foreach($item in $pagesList.Items) { $page=$item.Url GetWebpartInfoInOnePage($page) } } $sitePagesList=$web.Lists["Site Pages"] if($sitePagesList -ne $null) { foreach($item in $sitePagesList.Items) { $page=$item.Url GetWebpartInfoInOnePage($page) } } $web.Dispose() } $site.Dispose() } } } if ($help) { GetHelp; Continue } else { Start-Transcript -path "result.txt" -force RahulPublishingPageWebParts Stop-Transcript }
这个脚本最后会导出一个列表,将列表中的结果放入Excel在使用PowerPivot做出图表就可以了,这样比较方便省力,效果可以如下图。至于具体的制作powerpivot的方法这里就不说了。
相关文章推荐
- VisualStudio2008环境下,使用WebPart实现自定义页面布局
- WebPart(SharePoint)中如何使用自定义的Javascript和css样式
- SharePoint 使用代码创建 SPWeb/SPSiite/SPWebApplication以及WebPart添加到页面与删除 (三)
- 如何使用SVG生成超酷的页面预加载素描动画效果
- sharepoint 2010 如何使用sharepoint多媒体视频播放media webpart功能
- WebPart(SharePoint)中如何使用自定义的Javascript和css
- (转)WebPart(SharePoint)中如何使用自定义的Javascript和css样式
- 使用PS切片工具进行切片生成div布局的页面的方法以及如何确定图片中某个点在图片中的位置
- sharepoint 2010 如何使用sharepoint多媒体视频播放media webpart功能
- 如何生成邮件使用的状况报告
- WebPart(SharePoint)中如何使用自定义的Javascript和css样式
- 关于asp.net(c#),webconfig中如何定义一个字符串让所有页面共同使用?
- 如何使用编译生成的release搭建nfs boot环境
- 如何使用 base 标签使页面中的所有标签在新窗口中打开
- SharePoint 使用代码创建 SPWeb/SPSiite/SPWebApplication以及WebPart添加到页面与删除 (一)
- sharepoint: 如何获取页面上webpart列表
- 如何在页面中使用sharepoint中的富文本编辑器控件
- sharepoint 2010 使用程序向页面添加webpart
- SharePoint 使用代码为页面添加WebPart
- sharepoint 2010 如何使用sharepoint多媒体视频播放media webpart功能