编写PowerShell脚本可以删除page中所有的webpart,也可以根据webpart的属性信息去删除特定的webpart。

下面的PowerShell脚本便是删除对应page中所有的webpart:

param(
[string] $webUrl = "http://........:11111/sites/mysite",
[string] $pageUrl = "/Pages/myPage1.aspx"
)
$web = Get-SPWeb $webUrl
[Microsoft.SharePoint.Publishing.PublishingWeb]$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web);
$allowunsafeupdates = $web.AllowUnsafeUpdates
$web.AllowUnsafeUpdates = $true
$list = $web.Lists["Pages"]
if($list){
$page = $web.GetFile($webUrl + $pageUrl)
}
$page.CheckOut()
$webpartmanager = $web.GetLimitedWebPartManager($page.URL, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
for($i=0;$i -lt $webpartmanager.WebParts.Count; $i++){
$webpartmanager.DeleteWebPart($webpartmanager.WebParts[$i]);
Write-Output "Deleted" $webpartmanager.WebParts[$i].title
}
if ($page.CheckedOutBy.UserLogin -eq $web.CurrentUser.UserLogin)
{
Write-Output $web.CurrentUser.UserLogin
$page.CheckIn("Page checked in automatically by PowerShell script")
Write-Output $page.Title"("$page.Name") has been checked in"
} $web.Update()
$web.AllowUnsafeUpdates = $allowunsafeupdates
$web.Dispose()

。。。。。。。。。

用PowerShell脚本删除SharePoint 的 Page中的WebPart的更多相关文章

  1. 用Feature的方式删除SharePoint2010的Page中重复的WebPart

    用Feature的方式删除SharePoint2010的Page中重复的WebPart. 代码如下所示: public class SupportCenterDuplicatedWebpartRemo ...

  2. 如何删除sharepoint列表List中的全部数据。

    可以使用excel,但是powershell会比较方便 (admin mode - Sharepoint powershell) [System.reflection.Assembly]::LoadW ...

  3. 用PowerShell脚本实现对SharePoint页面Title的修改

    存在这样一种情况,对应的page已经部署到product的SharePoint环境中,那么在部署下一个版本的时候就不允许把已经创建好的page删除再创建,因此page中修改过的属性就不能再次部署到Sh ...

  4. 如何在windows计划中调用备份sharepoint2010网站集的powershell脚本

    最近有个项目需要在在windows计划中使用powershell脚本备份sharepoint2010网站集,打开sharepoint的powershell执行命令管理界面的属性 查看: C:\Wind ...

  5. 如何通过PowerShell在Visual Studio的Post-build中预热SharePoint站点

    问题现象 Visual Studio在开发SharePoint的时候,发布部署包后,首次打开及调试站点页面的时候会非常的慢 解决方案 使用PowerShell脚本,加载SharePoint插件后遍历所 ...

  6. 在PowerShell脚本中集成Microsoft Graph

    作者:陈希章 发表于2017年4月23日 我旗帜鲜明地表态,我很喜欢PowerShell,相比较于此前的Cmd Shell,它有一些重大的创新,例如基于.NET的类型系统,以及管道.模块的概念等等.那 ...

  7. PowerShell 脚本中的密码

    引言 笔者在<PowerShell 远程执行任务>一文中提到了在脚本中使用用户名和密码的基本方式: $Username = 'xxxx' $Password = 'yyyy' $Pass ...

  8. powershell 定时删除脚本

    powershell  定时删除脚本 $today=Get-Date #"今天是:$today" #昨天 #"昨天是:$($today.AddDays(-1))" ...

  9. 技术分享:如何在PowerShell脚本中嵌入EXE文件

    技术分享:如何在PowerShell脚本中嵌入EXE文件 我在尝试解决一个问题,即在客户端攻击中只使用纯 PowerShell 脚本作为攻击负荷.使用 PowerShell 运行恶意代码具有很多优点, ...

随机推荐

  1. nginx 原理&知识

    2015年6月4日 17:04:20 星期四 发现两个关于nginx原理的系列文章, 非常好 http://blog.sina.com.cn/s/blog_6d579ff40100wi7p.html ...

  2. Java for LintCode 颜色分类

    给定一个包含红,白,蓝且长度为n的数组,将数组元素进行分类使相同颜色的元素相邻,并按照红.白.蓝的顺序进行排序. 我们可以使用整数0,1和2分别代表红,白,蓝. 解题思路: Java for Leet ...

  3. Javascript调用C#后台方法及JSon解析

    Javascript调用C#后台方法及JSon解析   如何使用Ajax 调用C# 后台方法. 本文目录 如何使用Ajax 调用C# 后台方法. 1.后台(.cs)测试方法 2.前台调用(javasc ...

  4. 【leetcode】Jump Game I & II (hard)

    Jump Game (middle) Given an array of non-negative integers, you are initially positioned at the firs ...

  5. LightOJ1336 Sigma Function(约数和为偶数的个数)

    Sigma Function Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit ...

  6. mysql无法启动

    当在安装mysql服务时,有时会遇到恶心的PID错误而导致安装后无法启动以下为针对mysql-5.5版本在安装mysql时所遇到的问题的解决方法. 1.可能是/usr/local/mysql/data ...

  7. ld returned 1 exit status"的解决办法

    在Linux下创建线程时,编译时会出现下面的错误,[root@linuxserver 807]# gcc -o 22 22.c/tmp/cc21HcoW.o(.text+0x4c): In funct ...

  8. 【转】Java高手真经全套书籍分享

    (转自:http://blog.sina.com.cn/s/blog_4ec2a8390101cd1n.html) 中文名: Java高手真经 原名: JAVA开发专家 作者: 刘中兵Java研究室 ...

  9. 51nod1019逆序数(归并排序/树状数组)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1019 题意:中文题诶- 思路: 方法1:归并排序- 归并排序过 ...

  10. 三、jQuery--jQuery基础--jQuery基础课程--第11章 jQuery 工具类函数

    1.获取浏览器的名称与版本信息 在jQuery中,通过$.browser对象可以获取浏览器的名称和版本信息,如$.browser.chrome为true,表示当前为Chrome浏览器,$.browse ...