转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

将创建好的content type(若是跨web application需要事先publish content type,并在Monitor中跑和Content type同步相关的job,这里我写好了一个脚本,一键执行所有和content type相关的jobs)添加到指定的SharePoint list中,代码如下(以下代码保存到桌面“AddCTToList.ps1”文件中):

Add-PSSnapin Microsoft.SharePoint.PowerShell

function AddCTToList()
{
$webUrl = Read-Host "Enter the web url"
$web = Get-SPWeb $webUrl
$ListTitle = Read-Host "Enter the list title"
$List = $web.Lists[$ListTitle]
if ($List -ne $null)
{
$List.ContentTypesEnabled = $true
$List.Update()
$CTName = Read-Host "Enter the content type name"
$CT = $web.ContentTypes[$CTName]
$List.ContentTypes.Add($CT)
$List.Update()
Write-Host "Content type " $CT.Name " added to list " $ListTitle -ForegroundColor Green
}
else
{
Write-Host "The list " $ListTitle " does not exist in site " $web.Title
}
} AddCTToList

按提示先后输入:站点的url,list的title,content type的名字。调用方法如下:

运行结果如下:

之后在SharePoint中相应list的list setting页面我们可以看到,content type已经成功加入:

SharePoint自动化系列——Add content type to list.的更多相关文章

  1. SharePoint自动化系列——Add/Remove "Record" from items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 目的:批量的将SharePoint items变成records或者将records变成普通的it ...

  2. SharePoint自动化系列——Add/Remove “Hold” from items

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 问题1: 1.如果SharePoint item被添加了hold,通过UI界面来对SharePoi ...

  3. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  4. SharePoint自动化系列——Error features自动deactivate

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ SharePoint Content Deployment prerequisite——Error ...

  5. SharePoint自动化系列——Site/Web/List级别的导航菜单

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 需求:在不同的测试用例中,对脚本中不确定的因素需要和用户交互来确定,比如选择哪个site,选择哪个 ...

  6. SharePoint自动化系列——Create a local user and add to SharePoint

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 实现过程:在本地创建一个local user并将该user添加到Administrators组中, ...

  7. SharePoint自动化系列——通过Coded UI录制脚本自动化创建SharePoint Designer Reusable Workflow

    Coded UI非常好,我开始还在想,怎么样能让一个通过SharePoint Designer创建的Workflow publish三百五十次?想不到一个好的方法,也不知道SharePoint Des ...

  8. SharePoint自动化系列——创建MMS terms

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ PowerShell脚本实现MMS group.termSet.terms的自动化创建: Add- ...

  9. SharePoint自动化系列——通过PowerShell创建SharePoint Lists

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 代码如下(保存到本地ps1文件中,右键run with PowerShell即可): Add-PS ...

随机推荐

  1. SQL 2008 数据库只读 修改

        先对数据库分离 数据库鼠标右键->任务->分离   将UsersDB.mdf UsersDB_log.LDF文件 属性->安全->编辑   两个文件的都要更改权限   ...

  2. SQL 简单查询语句 select

    select *from emp;//查询emp表内容

  3. asp,asp.net 以表格输出excel,数据默认科学计数的解决办法

    关键字:  style="vnd.ms-excel.numberformat:@" 问题:在用table仿excel生成中经常遇到类似于身份证的长整数类型excel默认当成科学计数 ...

  4. linux挂接U盘

    挂接U盘fdisk -lDisk /dev/sdd: 131 MB, 131072000 bytes/dev/sdd1 * 1 889 127983+ b Win95 FAT32#mkdir -p / ...

  5. 当执行php脚本时用户关闭浏览器会发生什么?

    2008年8月16日 1,152 views 发表评论 阅读评论 如果一段php脚本执行插入数据到mysql的操作. 一般情况下,由于php脚本在服务器上执行,此时用户虽然关闭了浏览器,但是服务器端的 ...

  6. Spark on Mesos部署

    一.Mesos的安装和部署 1.下载mesos源码和依赖包 部署环境 centOS 6.6 mesos-0.21.0 spark-1.4.1 因为mesos官方只提供源码,所以必须要自己进行编译安装使 ...

  7. paper 27 :图像/视觉显著性检测技术发展情况梳理(Saliency Detection、Visual Attention)

    1. 早期C. Koch与S. Ullman的研究工作. 他们提出了非常有影响力的生物启发模型. C. Koch and S. Ullman . Shifts in selective visual ...

  8. html5文件上传

    <!DOCTYPE html><html><head> <title>Html5 Ajax 上传文件</title></head> ...

  9. nginx 优化

    隐藏nginx版本号:在http标签内写server_tokens off; 隐藏apache版本号:ServerTokens Prod ServerSignature Off 更改nginx默认的用 ...

  10. CentOS修改主机名和网络信息

    1.修改主机名称 [root@centos ~]# vim /etc/sysconfig/network打开文件,修改以下内容并保存 NETWORKING=yes #使用网络 HOSTNAME=cen ...