Monthly Archives: June 2014


At work I typically deploy  WSP’s to our environments.

A situation came up where it was necessary to redeploy a WSP multiple times, maybe dozens, as a developer worked through an issue.

We needed a fast way to allow the developer to deploy the WSP’s, but with a catch – we couldn’t give him RDP access to the server, and I knew that meetings and such would prevent me from turning around the requests as quickly as needed.

The solution:


I configured this script to run as a scheduled task in Windows, running every 2 minutes.
(For help on scheduling a task, see Schedule your PowerShell Scripts using the Windows Task Scheduler and it’s accompanying 2 min video)

Notes are below the script so be sure to scroll down…

#purpose - check a directory for a file
#if found, update the solution, then move the file to a backup directory
#Jack Fruh 
Add-PSSnapin "Microsoft.SharePoint.Powershell" -erroraction Silentlycontinue
$dt = get-date -format "yyyyMMdd_hhmmtt"

$loc = get-location
$monitorfolder = "WSPDropFolder"
$archivefolder = "Archive"
$wsp = "Name.of.Your.wsp"
$source = "$($loc.path)\$monitorfolder\$wsp"
$dest = "$($loc.path)\$archivefolder\$($dt)_$wsp"

if (test-path $source)
    # allow enough time 
    # in case the file was being copied 
    # at the exact moment the script ran:
    sleep 10
    $dt = get-date -format "yyyyMMdd_hhmmtt"
    write-host "file $source found - deploying"
    Update-SPSolution -Identity $wsp -LiteralPath $source -GacDeployment
    move-item $source $dest
    $EmailFrom = ""
    $EmailTo = ""
    $EmailCC = ""
    $EmailSubject = "Code moved to Stage"
    $EmailBody = "Hi There, at $dt $source was updated in stage, and moved to $dest"
    $SMTPServer = ""

    Send-MailMessage -From $EmailFrom -To $EmailTo -CC $EmailCC -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer	  
    write-host "No File to deploy found at $source"

The WSPDropFolder is shared (ie a windows shared folder on the server) with the developer – the developer is the only one who has access so that should help on the security side of things.

The Script checks to see if the file is there, it’s looking for a specific file, by name – this helps ensure the script is only used to deploy the agreed upon solution and not used for general deployments.

After the Script updates the WSP in sharepoint, it moves it to the Archive folder and date stamps it.

It then finishes things up by sending the developer, and myself an email so we both know the deployment completed.

“Using” the script is simple -the developer copies the WSP for deployment to the WSPDropFolder, then, within 2 minutes the script picks up the file and deploys it, the developer will see the folder is again empty, and will receive an email confirmation.

If the developer needs to redeploy, he just puts a new file in the WSPDropFolder and the process repeats.

It’s worked out great so far, allowing the developer to make and test multiple revisions to his code quickly, and without my intervention.

– Jack