Per restare in tema di migrazione (vedi
Creare una Web Application di SharePoint 2010 tramite PowerShell), ecco uno script
PowerShell per
SharePoint 2010, che permette di aggiungere (Add) e installare (deploy) una serie di solution (file WSP)
#aggiunge e installa le solutions
$ErrorActionPreference = "Stop"
$err = 0
#percorsi dove sono presenti le solutions
$solutions = @(
"\\sgartshare\d$\Utility\SolutionsMOSS2007\solution1.wsp"
, "\\sgartshare\d$\Utility\SolutionsMOSS2007\CRW\solution2.wsp"
, "\\sgartshare\d$\Utility\SolutionsMOSS2007\FGV\solution3.wsp"
)
Write-host "Aggiungo le solutions" -ForeGroundColor Green
Write-host "======================================================";
$solutions | foreach {
$sol = [System.IO.Path]::GetFileName($_);
Write-host "Aggiungo la solution: $sol";
Write-host "Path: $_";
$name = Test-Path $_
$Solution = Get-SPSolution | ? {$_.Name -eq $Sol }
if($solution -ne $null) {
Write-Host "solution esistente" -ForeGroundColor blue
}else{
if (-not $name){
Write-Host "solution non trovata" -ForeGroundColor Red
$err = $err + 1
} else {
#aggiungo la solution
Add-SPSolution $_
#Remove-SPSolution $sol -confirm:$false
}
}
Write-host "------------------------------------------------------";
}
Write-host "Installo le solutions" -ForeGroundColor Green
Write-host "======================================================";
#specificare la modalità di deploy: url specifica, Globally oppure AllWebApplications
$installs = @(
"solution1.wsp, Globally"
,"solution2.wsp, http://sharepoint2010.sgart.it/"
,"solution3.wsp, AllWebApplications"
)
$installs | foreach {
$temp = $_.split(",")
#nome della solution
$sol = $temp[0].trim()
#tipo/url del deploy
$type = $temp[1].trim()
Write-host "Installo la solution: $sol";
Write-host "Tipo: $type";
$Solution = Get-SPSolution | ? {$_.Name -eq $Sol }
if($solution.Deployed -eq $true) {
Write-host "Deployed " -ForeGroundColor Blue
} else {
try{
if ($type -eq "globally"){
Write-host "Deploy: Globally"
Install-SPSolution -Identity $sol –GACDeployment
} else {
if ($type -eq "AllWebApplications"){
Write-host "Deploy: Globally"
Install-SPSolution -Identity $sol -AllWebApplications –GACDeployment
} else {
$url = $type
Write-host "Deploy: WebApplication"
Install-SPSolution -Identity $sol –WebApplication $url –GACDeployment
}
}
$i = 0;
#attendo la fine del deploy della solution perun massimo di 2 x 100 = 200 sec
while ($Solution.Deployed -eq $false -and $i -lt 100)
{
write-host "." -NoNewline
Start-Sleep 2
$Solution = Get-SPSolution | ? {$_.Name -eq $Sol }
$i = $i+1
}
} catch {
write-host $error[0] -ForeGroundColor Red;
$err = $err + 1
}
}
Write-host "------------------------------------------------------";
}
if ($err -gt 0){
Write-Host "Terminato con ERRRORI: $err" -ForeGroundColor Red
}
Lo
script aggiunge le solution non ancora presenti in
SharePoint, successivamente esegue il deploy, delle solution non deploiate, secondo le modalità indicate.