Il est fréquent de vouloir exporter une solution depuis le catalogue de solution:
- Sauvegarde avant une installation,
- Récupération d’une solution pour analyse,
- …
La récupération d’une solution est assez simple, mais nécessite l’exploitation de PowerShell.
Export d’une unique solution
Voici un exemple de récupération d’une solution :
1 2 |
$sol = Get-SPSolution MaSuperSolution.wsp $sol.SolutionFile.SaveAs("c:\Backups\MaSuperSolution.wsp") |
En effet, l’objet SPSolution possède une propriété SolutionFile de type SPPersistedFile.
Export de l’ensemble des solution
On peut alors aisément en déduire un script one-line pour dumper l’ensemble des solutions d’une ferme dans le dossier courant :
1 |
Get-SPSolution | % { $_.SolutionFile.SaveAs("$pwd\$($_.Name)") } |
Ou encore créer une fonction avancée pour industrialiser la procédure :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
function Export-SPSolution{ param( [Parameter(Mandatory=$true, Position=0, ValueFromPipeline=$true)] [Microsoft.SharePoint.PowerShell.SPSolutionPipebind[]]$Solution, [Parameter(Position=1)] [string]$Outdir = $pwd ) process{ $sol = $Solution.Read() $outfile = Join-Path $Outdir $sol.Name $sol.SolutionFile.SaveAs($outfile) New-Object PSObject -Property ([ordered]@{ Solution = $Sol.Name OutFile = $outfile }) } } |
Qui peut alors s’utiliser de multiples manières (exemples) :
1 2 3 4 5 6 7 |
Export-SPSolution MaSuperSolution.wsp Export-SPSolution MaSuperSolution -Outdir C:\temp\data Get-SPSolution | Export-SPSolution Get-SPSolution | ? { $_.Name -match "MaSuper" } | Export-SPSolution -Outdir C:\temp\data |
[?]