SharePoint 2010 PowerShell 系列 之 备份、还原、部署 .WSP

PowerShell系列目录     

      最近在部署测试环境,就顺便把PowerShell 的部署命令了解一下,下面给详细讲解一下关于 PowerShell如何备份、还原及部署.WSP,有人会说,这样的操作通过管理中心可以很容易完成,为什么还要写命令呢?

   原因:界面操作是简单,但是执行的时间比较长,没有用命令速度快。命令一次写完后,以后直接拿来用就可以了,一次付出,终身获益......

第一:备份

# Check to ensure Microsoft.SharePoint.PowerShell is loaded
$Snapin = get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if($Snapin -eq $null){
    Write-host "Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$siteName = "http://SP:999"
$path = "C:\site_name_999_test.bak"

Write-Host "Starting backup SPSite " $siteName ",please waiting......" -foregroundcolor yellow
Backup-SPSite $siteName  -Path $path -Force
Write-Host "Backup SPSite " $siteName "sucessful!" -foregroundcolor green

第二:还原

# Check to ensure Microsoft.SharePoint.PowerShell is loaded
$Snapin = get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if($Snapin -eq $null){
    Write-host "Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}

$siteName = "http://SP:666"
$path = "C:\Project_201208231718.bak"

Write-Host "Starting resotre SPSite " $siteName ",please waiting......" -foregroundcolor yellow
Restore-SPSite $siteName  -Path $path -Force
Write-Host "Restore SPSite " $siteName "sucessful!" -foregroundcolor green

第三:部署WSP

# Check to ensure Microsoft.SharePoint.PowerShell is loaded
$Snapin = get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if($Snapin -eq $null){
    Write-host "Loading SharePoint Powershell Snapin"
    Add-PSSnapin "Microsoft.SharePoint.Powershell"
}


$solutionPortalPath = "C:\aa.wsp"
$solutionVendorPath = "C:\bb.wsp"

$solutionPortal = "aa.wsp"
$solutionVendor = "bb.wsp"

# Add SPSolution 
Write-Host "Starting Add Solution,please waiting......" -foregroundcolor yellow
Add-SPSolution $solutionPortalPath
Add-SPSolution $solutionVendorPath
Write-Host "Solution Add Sucessful!" -foregroundcolor green

# Deploy Solution
Install-SPSolution –Identity SharePoint2010Solution.wsp –WebApplication http://myserver –GACDeployment

# Deploy  Sandbox Solution
Install-SPUserSolution –Identity SharePoint2010Solution.wsp     –WebApplication http://myserver  –GACDeployment

# Update Solution Package
Write-Host "Starting Update Solution,please waiting......" -foregroundcolor yellow
Update-SPSolution –Identity $solutionPortal –LiteralPath $solutionPortalPath –GacDeployment
Update-SPSolution –Identity $solutionVendor –LiteralPath $solutionVendorPath –GacDeployment
Write-Host "Solution Update Sucessful!" -foregroundcolor green

# Uninstall Solution Package
Uninstall-SPSolution –Identity MySharePointSolution.wsp –WebApplication  http://myserver

# Remove Solution Package
Remove-SPSolution–Identity MySharePointSolution.wsp

以上操作都比较简单,就没有写注释,相信大家一看就懂。

你可能感兴趣的:(SharePoint)