博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PowerShell实现基于SharePoint的网站HomePage Auto-Upgrade Solution
阅读量:7107 次
发布时间:2019-06-28

本文共 3657 字,大约阅读时间需要 12 分钟。

*** Solution Auto-Upgrade Solution

 PS:该项目为公司项目,我还是给他的名字屏蔽掉吧,这是我用PowerShell写的一个自动化升级工具,此为三部自动化工具的第一部。主要是用PowerShell自动完成下载,解压缩一直到部署solution到SharePoint这一过程。

​*** Solution Auto-Upgrade Script

​Home Page Module Demo:

注:目前只支持HomePage Module,如果修改里面的可替换链接和字符串分析和路径分析的话将可以用在***所有部署Solution的模块,以下是文档内容。

User Guide:

1. Right click the script and run the script with PowerShell.

2. Input the package address and press the "Enter".

3. "Save as" the file under the path "C:\ HomePageSolution" (already been created automatically). 

Result:

The solution will be upgraded automatically in the SharePoint Farm.

Script: 

<#ftp function reference#>Function Invoke-FtpLogin{Param([parameter(Mandatory = $true)]      [string]$Site = "ftp://10.1.4.5/Monetary_Authority_of_Singapore/HomePageSolution/DailyBuild",      [string]$User = "Anonymous",      [string]$Pass = "",      [int]$Port=21,      [int]$TimeOut=3000,      [int]$ReadWriteTimeout=10000)Write-Host "Get FTP site dir listing..."# Do directory listing$FTPreq = [System.Net.FtpWebRequest]::Create($Site)$FTPreq.Timeout = $TimeOut                          # msec (default is infinite)$FTPreq.ReadWriteTimeout = $ReadWriteTimeout        # msec (default is 300,000 - 5 mins)$FTPreq.KeepAlive = $false                          # (default is enabled)$FTPreq.Credentials = New-Object System.Net.NetworkCredential($User,$Pass)$FTPreq.Method = [System.Net.WebRequestMethods+FTP]::ListDirectorytry{    $FTPres = $FTPreq.GetResponse()    Write-Host "$User _ $Pass OK"    $success = $true#Write-Host $FTPres.StatusCode -nonewline#Write-Host $FTPres.StatusDescription $FTPres.Close()}catch{   Write-Host "FAILED: $_"   $success = $false}} <#Unzip function reference#>Function Unzip-File(){    param([string]$ZipFile,[string]$TargetFolder)    #Make sure the file must be existed.    if(!(Test-Path $TargetFolder))    {        mkdir $TargetFolder    }    $shellApp = New-Object -ComObject Shell.Application    $files = $shellApp.NameSpace($ZipFile).Items()    $shellApp.NameSpace($TargetFolder).CopyHere($files)} <#HomePage Solution Auto-Update#>#If not admin, open the ps1 with admin again.$currentWi = [Security.Principal.WindowsIdentity]::GetCurrent()$currentWp = [Security.Principal.WindowsPrincipal]$currentWiif( -not $currentWp.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)){ $oldPid = $pid $currentFile = $MyInvocation.MyCommand.Path Start-Process "$psHome\powershell.exe" -ArgumentList $currentFile -verb runas kill $oldPid}#Admin runs the script.Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinueNew-Item c:\HomePageSolution -ItemType directory -ErrorAction SilentlyContinue$ie = new-object -com InternetExplorer.Application<#User input the newest package address#>$packageURL = Read-Host "Please input the URL of the HomePage package"$timeURL = $packageURL.substring(75,10)$pieces = $timeURL -Split "-"$cake = -join $pieces$fileURL = "APPS***HomePageSolution_1.0.0.6_" + $cake +".zip"$downloadURL = $packageURL + "/" + $fileURL$ie.Navigate2($downloadURL)$ie.Visible = $true<#Wait until the download has been finished.#>do{ Start-Sleep -m 3000}until(Get-ChildItem c:\HomePageSolution|where{
$_.name -like $fileURL})<#Unzip the package after the download has been finished.#>$UnzipPath = "c:\HomePageSolution\" + $fileURL$goalPath = "c:\HomePageSolution\" + "APPS***HomePageSolution_1.0.0.6_" + $cakeUnzip-File -ZipFile $UnzipPath.tostring() -TargetFolder $goalPath.tostring()$updatePath = $goalPath + "\" + "APPS***HomePage.wsp"Update-SPSolution -Identity APPS***HomePage.wsp -LiteralPath $updatePath​ -GACDeploymentRead-Host "Press any key to quit"​

 

转载地址:http://bouhl.baihongyu.com/

你可能感兴趣的文章
重拾web开发-DIV+CSS基础(总结)
查看>>
确定查询各阶段消耗的时间
查看>>
Linux学习之路(三)Shell脚本初探
查看>>
CSS-三栏响应式布局(左右固宽,中间自适应)的五种方法
查看>>
Total Commander 7.55a 个人使用设置 及 快捷键 备忘
查看>>
ROS开发文档
查看>>
mysql innodb与myisam存储引擎的区别
查看>>
Wannafly挑战赛25 A 因子 数学
查看>>
Shell命令-文件及内容处理之grep(egrep)、join
查看>>
CentOS7 防火墙
查看>>
svn项目冲突时显示无法加载项目的解决方法
查看>>
2019-4-22 jdbc学习笔记
查看>>
7 行代码优雅地实现 Excel 文件导出功能?
查看>>
thinkphp3.2.3 无法调用带下划线的模型
查看>>
RK 3299 Ubuntu 配置密钥
查看>>
react-hooks: CSSProperties
查看>>
abp 关闭审计日志
查看>>
迭代器模式 Iterator 行为型 设计模式(二十)
查看>>
解决walle报错:宿主机代码检出检测出错,请确认svn用户名密码无误
查看>>
svn使用openldap验证apache访问方式
查看>>