PowerShell实现基于SharePoint的网站HomePage Auto-Create Solution
2015-01-15 10:43
363 查看
*** HomePage Auto-Create Solution
Monday, January 12, 2015PS:该项目为公司项目,我还是给他的名字屏蔽掉吧,这是我用PowerShell写的一个自动化升级工具,此为三部自动化工具的第二部。主要是用PowerShell去创建一个SharePoint页面,并且按照规定顺序对其自动进行配置。
Automation :
本次自动化代替操作完成的是HomePage配置文档中设置步骤的1到9步(属于做数据阶段),由于HomePage结合的模块众多,添加web parts到页面的过程需要调用Leo哥写的各种后台过程,光靠调用SharePoint API是无法完成的,所以第九步后半部分的“将webpart一一对应的加入WebPart Zone中”这一过程为手动添加过程。(属于测试阶段,检查咱们添加的后台过程是否正常运行,1. My Documents web part的title url是否自动添加到web part setting中;2. 保存并点击title,检查header能顺利实现跳转;2. 检查My Documents web part和Site Management web part的header是否包含特定的黑框样式。)整个HomePage部署自动化包含三个阶段,第一阶段(详见上一篇)和第二阶段都已经完成了,最后一个阶段就是配置web part和修改web part信息的过程我也会找时间尝试写成自动配置的脚本。(感谢大神超哥@Leo Jiang巨指点,虽然这次没试上web part的导出导入和API,不过下次写web part的配置过程时就可以派上用途啦。)
HomePage设置步骤:
Add Solution APPS***HomePage.wsp to FarmDeploy solution到homepage所在web application
创建Site Collection,作为Home Page使用的Site Collection。
进入Site Setting页面,点击Site collection features,激活SharePoint Server Publishing Infrastructure,Custom Page Layout Feature
返回Site Setting页面,点击Manage Site features,激活SharePoint Server Publishing
返回Site Setting页面,点击Site collection features,激活Home Page Web Part Feature
设置Site的***ter page为Seattle
点击Site Contents,进入Pages Library,点击Ribbon上的New Documents,创建Article Page,Page Layout选择*** Home Page
创建好Home Page对应的publishing page
METHOD: Right click the tool and run it as administrator.
Result: The *** Home Page will be created and open automatically.
Script Code:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue $Time = Get-Date $Today = $Time.year.toString() + "." + $Time.month.toString() + "." + $Time.day.toString() $TodayIs = "Today is " + $Today.toString() $TodayIs $siteURL = "https://teamsite.migration.net/sites/" + $Today + ".HomePage" Write-Host "Today's HomePage is creating..." New-SPSite -URL $siteURL -OwnerAlias "soe\tuser2" -Language 1033 -CompatibilityLevel 15 -Template "STS#0" $HomePageSiteCollection = Get-SPSite -Identity $siteURL Write-Host "The HomePage site collection has been created successfully." #Enable the site collection level publishing feature Write-Host "Enabling the site collection level publishing feature..." Enable-SPFeature -Id F6924D36-2FA8-4f0b-B16D-06B7250180FA -Url $siteURL Write-Host "The site collection level publishing feature has been enabled." #Enable the *** custom page layout feature Write-Host "Enabling the *** custom page layout feature..." Enable-SPFeature -Id AFBAA18A-CD2A-4866-AE01-EB1B35778687 -Url $siteURL Write-Host "The *** custom page layout feature has been enabled." #Enable the web level publishing feature Write-Host "Enabling the web level publishing feature..." Enable-SPFeature -Id 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb -Url $siteURL Write-Host "The web level publishing feature has been enabled." #Enable the HomePage web part feature Write-Host "Enabling the HomePage feature..." Enable-SPFeature -Id 8efd39bf-e322-41a6-80c8-a82c531f0fa1 -Url $siteURL Write-Host "The HomePage feature has been enabled." #Change the system ***ter page Write-Host "Changing the system ***ter page into seattle..." $HomePageSiteCollection.rootweb.***terUrl = "/sites/" + $Today + ".HomePage/_catalogs/***terpage/seattle.***ter" Write-Host "The system ***ter page has been changed." #Change the site ***ter page Write-Host "Changing the site ***ter page into seattle..." $HomePageSiteCollection.rootweb.Custom***terUrl = "/sites/" + $Today + ".HomePage/_catalogs/***terpage/seattle.***ter" Write-Host "The site ***ter page has been changed." #Save the change Write-Host "Save the changes..." $HomePageSiteCollection.rootweb.update() Write-Host "The changes has been saved to the HomePage's site collection." #Create the HomePage Write-Host "Creating the HomePage automatically..." $spWeb = $HomePageSiteCollection.rootweb $pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb) $pageLayout = $pubWeb.GetAvailablePageLayouts()|where{$_.name -like '*DMSHome*'} $HomePage = $pubWeb.AddPublishingPage("***HomePage.aspx",$pageLayout) #filename need end with .aspx extension $HomePage.Update() $HomePage.CheckIn("") $HomePage.ListItem.File.Publish("") $spWeb.Dispose() Write-Host "The HomePage has been created successfully..." $HomePageURL = $siteURL + "/Pages/***HomePage.aspx" $shell = New-Object -ComObject Shell.Application $shell.Open($HomePageURL) Read-Host "Press any key to continue"
相关文章推荐
- PowerShell实现基于SharePoint的网站HomePage Auto-Upgrade Solution
- PowerShell实现基于SharePoint的网站HomePage Auto-Configure Solution
- 在基于Form验证的SharePoint网站中实现用户口令过期策略
- 使用stsadm.exe工具实现SharePoint网站备份还原
- 一步一步SharePoint 2007之二十:解决实现注册用户后,自动具备访问网站的权限的问题(2)——配置Role
- VS2005 中通过MasterPage来更方便实现网站模板替换
- 基于SHAREPOINT 实现简单的进销存
- 一步一步SharePoint 2007之十九:解决实现注册用户后,自动具备访问网站的权限的问题(1)——配置Provider
- 领先的易物网站-舍得网基于J2ee Resin实现的技术内幕(一)
- 一步一步SharePoint 2007之十七:解决实现Form认证后无法再用SharePoint Designer编辑网站的问题
- 一步一步SharePoint 2007之十九:解决实现注册用户后,自动具备访问网站的权限的问题(1)——配置Provider
- 一步一步SharePoint 2007之十九:解决实现注册用户后,自动具备访问网站的权限的问题(1)——配置Provider
- 使用新的方法来实现SharePoint网站日志更新
- 一步一步SharePoint 2007之二十:解决实现注册用户后,自动具备访问网站的权限的问题(2)——配置Role
- 一步一步SharePoint 2007之二十一:解决实现注册用户后,自动具备访问网站的权限的问题(3)——创建用户
- 一步一步SharePoint 2007之二十一:解决实现注册用户后,自动具备访问网站的权限的问题(3)——创建用户
- 一步一步SharePoint 2007之十七:解决实现Form认证后无法再用SharePoint Designer编辑网站的问题
- .Net 2005 中通过MasterPage来更方便实现网站模板替换
- 一步一步SharePoint 2007之二十:解决实现注册用户后,自动具备访问网站的权限的问题(2)——配置Role
- 一步一步SharePoint 2007之十七:解决实现Form认证后无法再用SharePoint Designer编辑网站的问题