本文共 3657 字,大约阅读时间需要 12 分钟。
PS:该项目为公司项目,我还是给他的名字屏蔽掉吧,这是我用PowerShell写的一个自动化升级工具,此为三部自动化工具的第一部。主要是用PowerShell自动完成下载,解压缩一直到部署solution到SharePoint这一过程。
*** Solution Auto-Upgrade Script
Home Page Module Demo:
注:目前只支持HomePage Module,如果修改里面的可替换链接和字符串分析和路径分析的话将可以用在***所有部署Solution的模块,以下是文档内容。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).
The solution will be upgraded automatically in the SharePoint Farm.
<#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/