您的位置:首页 > 运维架构 > Shell

【SharePoint学习笔记】第2章 SharePoint Windows PowerShell 指南

2014-05-21 09:48 537 查看
快速了解Windows PowerShell

从SharePoint 2010开始支持PowerShell,仍支持stsadm.exe工具;
可以调用.NET对象、COM对象、exe文件传参;
控制台执行,批处理执行;
支持管道



书写Windows PowerShell脚本
后缀名:.psl,纯文本文件;
Write-Host "Hello World!"

使用Windows PowerShell集成脚本开发环境(ISE)
缺省未安装 可从管理工具/控制面板 增加
F5执行,断点调试

简单示例:
$sum1=1+2
$sum2=3+4
$sum3=$sum1+$sum2
write-host $sum3

流程控制:
$names = "YangGuo","XiaoLongNv","GuoJing","HuangRong";
foreach($name in $names)
{
write-host $name
}

调用.NET对象
$data=New-Object -TypeName System.DataTime -ArgumentList @(2014,4,20,17,46,0)
$message = "This Day is "+ $data.ToLongDateString()
Write-host $message

调用.NET对象静态属性
$today = [System.DateTime]::Today
Write-Host $today.ToLongDateString() 2014年5月20日
Write-Host $today.ToString("MM/dd/yy") 05/20/14
Write-Host $today.AddDays(100).ToString("MMMM d") 八月 28

调用COM对象
$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.Navigate("http://mail.163.com")
$ie.visible = $true

SharePoint Windows PowerShell 插件
一系列核心库、命令集 - PowerShell 核心库SharePoint.PowerShell
插件 - SharePoint

使用Windows PowerShell 管理SharePoint
创建Web应用程序
$name = "Web Application from PowerShell"
$port = 10000
$url = "http://john-pc"
$appPoolName = "SharePoint - 10000"
$appPoolAccount = "John-pc\SPService10000"
New-SPWebApplication -Name $name -Port $port -Url $url -ApplicationPool $appPoolName -ApplicationPoolAccount $appPoolaccount

创建网站集

$title = "Creating site collection from PowerShell"
$url = "http://john-pc:10000"
$owner = "john-pc\Administrator"
$template = "STS#1"
#delete target site collection if it exists
$targetSite = Get-SPSite | Where-Object{$_.Url -eq $url}
if ($targetSite -ne $nullj)
{
Rmove-SPSite -Identity targetSite -Confirm:$false
}
#create new site collection
New-SPSite -URL $url -Name $title -OwnerAlias $Owner -Template $template

常用模板
STS#0 组站点
STS#1 空白站点
STS#2 文档合作站点
MPS#0 基本会议站点
MPS#1 空白会议站点
MPS#2 决议会议站点
MPS#3 社交会议站点
MPS#4 多页会议站点
Centrladmin#0 中央管理站点
Wiki#0 维基站点
Blog#0 博客站点
SGS#0 组协作站点
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: