In case of big SharePoint Farms with large application domain we need to add multiple solutions, Doing it manually will be a lot tough and time consuming task. So a more manageable way could be to create a PowerShell script, that runs on the Farm to add the listed wsp solutions. I created one of such solution for a client who had around 50-60 such solutions. Below is the script that you can use to add wsp's solutions to SharePoint Farm. This script should be placed inside a folder along with the wsp solutions which needs to be added.
Copy-Paste the below script in a text file and rename its extension to - *.ps1
$dir =
$(gl)
$list = Get-ChildItem $dir | where {$_.extension -eq
".wsp"}
foreach($my_file in Get-ChildItem $list)
{
write-host
$my_file.Name
$currentDir
= Get-Location
[string]$packageName =
$my_file.Name
$solution
= Get-SPSolution
$packageName -ErrorAction
SilentlyContinue
if ($solution
-ne $null)
{
Write-Host
Write-Host "The solution $packageName already exists." -foregroundcolor
Red
}
else
{
[string]$packagePath =
$currentDir.Path
+ "\"
+ $packageName
Write-Host
Write-Host
"Adding solution... $packageName..."
-foregroundcolor Yellow
$addedsolution
= Add-SPSolution
$packagePath
if
($addedsolution -ne
$null)
{
Write-Host
"Solution added successfully... $packageName..."
-foregroundcolor Green
}
else
{
Write-Host
"ERROR in adding solution... $packageName..."
-foregroundcolor Red
}
}
}
No comments:
Post a Comment