2
Reply

Remote Server Deployment

Ravi Kumar

Ravi Kumar

Jul 11 2017 8:29 AM
218
Hi All,
 
I have 2 servers in same LAN, one is Dev and other one is Test Server. i wanted to deploy *.wsp's into Test server by using powershell from Dev server remotely.
 
am unable to achieve this  within Dev server i can able to deploy for Dev server sites.
 
I script file is as below. 
 
#Deployment Scripts for Failover JOb#
function WaitForJobToFinish([string]$SolutionFileName)
{
$JobName = "*solution-deployment*$SolutionFileName*"
$job = Get-SPTimerJob | ?{ $_.Name -like $JobName }
if ($job -eq $null)
{
Write-Host 'Timer job not found'
}
else
{
$JobFullName = $job.Name
Write-Host -NoNewLine "Waiting to finish job $JobFullName"
while ((Get-SPTimerJob $JobFullName) -ne $null)
{
Write-Host -NoNewLine .
Start-Sleep -Seconds 2
}
Write-Host "Finished waiting for job.."
}
}
Add-PsSnapin Microsoft.SharePoint.PowerShell
Function DeployFailover{
$currentDir= Get-Location
$targetWebApp=Read-Host -Prompt 'Please input Web Application Name eg (http://myserver:2222/)'
$solutionName=Read-Host -Prompt 'Please input Solution Name eg (Sharepoint.wsp)'
$solutionPath="$currentDir\$solutionName"
$featureName=Read-Host -Prompt 'Please input Feature Name eg (Sharepoint)'
$featureID=Read-Host -Prompt 'Please input Feature ID eg (b4940aca-9c55-4631-b094-c6a198e390fb)'
Write-Host 'Going to disable feature'
try
{
Disable-SPFeature –Identity $featureID –url $targetWebApp -Confirm:$false -force
}
Catch [system.exception]
{
Write-Host 'Feature doeasnot exist to disable'
}
Write-Host 'Going to uninstall feature'
uninstall-spfeature $featureName -confirm:$false -force
Write-Host 'Going to uninstall solution'
Uninstall-SPSolution $solutionName -confirm:$false
Write-Host 'Waiting for job to finish'
WaitForJobToFinish
Write-Host 'Going to remove solution'
Remove-SPSolution $solutionName -confirm:$false -force
Write-Host 'Going to add solution'
Add-SPSolution $solutionPath
Write-Host 'Going to install solution to Target web application'
Install-SPSolution -identity $solutionName -GACDeployment -Confirm:$false -force
Write-Host 'Waiting for job to finish'
WaitForJobToFinish
Write-Host 'Going to enable Feature'
Enable-SPFeature –Identity $featureID –url $targetWebApp
}
Write-Host 'SharePoint Deployment Started'
#Copying the wsp(s) from client machine to target server
#$SourceUrl = Read-Host "Please paste your source wsp's Url." #Where your wsp pasted
#$DestinationUrl = Read-Host "Please paste where you want to copy the wsp."
#Copy-Item "$SourceUrl\*" -Destination $DestinationUrl -ErrorAction SilentlyContinue
$compName=Read-Host -Prompt 'Please input Remote Cumputer Name'
$user=Read-Host -Prompt 'Please input User Name'
Enter-PSSession -ComputerName $compName -Credential $user
For ($i=0; $i -lt 2; $i++) {
DeployFailover
}
Remove-PsSnapin Microsoft.SharePoint.PowerShell
 

Answers (2)