*** Solution Auto-Upgrade Solution

Tuesday, January 06, 2015

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]::ListDirectory

try

{

    $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]$currentWi

if( -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 SilentlyContinue

New-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_" + $cake

Unzip-File -ZipFile $UnzipPath.tostring() -TargetFolder $goalPath.tostring()

$updatePath = $goalPath + "\" + "APPS***HomePage.wsp"

Update-SPSolution -Identity APPS***HomePage.wsp -LiteralPath $updatePath​ -GACDeployment

Read-Host "Press any key to quit"​

PowerShell实现基于SharePoint的网站HomePage Auto-Upgrade Solution的更多相关文章

  1. PowerShell实现基于SharePoint的网站HomePage Auto-Configure Solution

    Home Page Web Parts Auto-Configuration PS:该项目为公司项目,我还是给他的名字屏蔽掉吧,这是我用PowerShell写的一个自动化升级工具,此为三部自动化工具的 ...

  2. PowerShell实现基于SharePoint的网站HomePage Auto-Create Solution

    *** HomePage Auto-Create Solution Monday, January 12, 2015   PS:该项目为公司项目,我还是给他的名字屏蔽掉吧,这是我用PowerShell ...

  3. 实现一个基于 SharePoint 2013 的 Timecard 应用(上)

    在 SharePoint 2013 上面实现一个 Timecard 应用的想法来自一个真实的需求,而实现的方案在我脑海里面盘旋已经很久了,终于这几天准备安排点儿时间将它实现出来. “ We start ...

  4. 优化移动设备上SharePoint 2013网站

    优化移动设备上SharePoint 2013网站 本文由SPFarmer翻译自Waldek Mastykarz的文章 移动市场在持续的增长.在不远的将来,使用移动设备浏览站点将会超过电脑.为了保证用户 ...

  5. SharePoint 开启网站匿名访问图文详解

    SharePoint 开启网站匿名,需要先开启web application的匿名访问,然后开启site的匿名访问.特别的,site可以选择整个网站开启或者列表和库开启匿名,如果选择列表和库开启匿名, ...

  6. 基于jQuery的网站首页宽屏焦点图幻灯片

    今天给大家分享一款基于jQuery的网站首页宽屏焦点图幻灯片.这款焦点图适用浏览器:IE8.360.FireFox.Chrome.Safari.Opera.傲游.搜狗.世界之窗.效果图如下: 在线预览 ...

  7. 基于jQuery商城网站全屏图片切换代码

    基于jQuery商城网站全屏图片切换代码.这是一款商城网站全屏多张图片滑动切换代码.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="slid ...

  8. SharePoint 2013网站突然不能登录了。

    SharePoint 2013网站突然不能登录了,访问的时候,总是报错: The list has not shared with you.   原因: 原来我不知道什么时候把web applicat ...

  9. 在PowerShell中操作SharePoint对象

    1. 用PowerShell创建一个SharePoint内容对象创建一个自定义列表:$SPSite = New-Object Microsoft.SharePoint.SPSite("htt ...

随机推荐

  1. 【DeepLearning】Exercise:PCA in 2D

    Exercise:PCA in 2D 习题的链接:Exercise:PCA in 2D pca_2d.m close all %%=================================== ...

  2. java 记录一下socket的server与client

    package com.test.server; import java.io.IOException; import java.net.ServerSocket; import org.apache ...

  3. 如何用STAF进行自动化测试分布式运行

    本文的目的在于引导读者去了解STAF及如何调用其接口去实现自动化测试的分布式动行. 提到分布式运行,很多人想到了Jenkins,Jenkins里面有个node插件,可以去分派任务给slave,Jenk ...

  4. C语言学习笔记 (008) - C语言字符串操作总结大全(超详细)(转)

    1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度 ...

  5. 10个很棒的学习Android 开发的网站

    1. Android Developers 作为一个Android开发者,官网的资料当然不可错过,从设计,培训,指南,文档,都不应该错过,在以后的学习过程中慢慢理解体会. 2. Android Gui ...

  6. 【Hibernate】数据Session对象的常规操作收集

    因为Hibernate是ORM(对象关系映射)的,所以程序员是不需要写Sql语句的.所有的操作都是通过对对象的操作. 1,原生Session 事务管理 Transaction tx = session ...

  7. 【Spring】Spring之浅析Spring框架的搭建

    Spring是什么 Spring是一个开源的容器框架,用于配置bean并且维护bean之间关系的.其主要的思想就是IOC(Inversion Of Control,控制反转)或者称作DI(Depend ...

  8. @weakify, @strongify

    我们知道,在使用 block 的时候,为了避免产生循环引用,通常需要使用 weakSelf 与 strongSelf,写下面这样的代码 __weak typeof(self) weakSelf = s ...

  9. Docker LNMP环境搭建

    原文地址:https://www.awaimai.com/2120.html 1 快速使用 2 安装docker和docker-compose 3 使用国内镜像仓库 4 目录说明 4.1 目录结构 4 ...

  10. mysql常用查询语句

    一.查询指定schema下表的个数 select count(TABLE_NAME) from information_schema.tables where table_schema="d ...