SharePoint WSP Solutions Backup and Retention

Hi All,

Sharing a recently created script by our Team with below requirement.

ALL WSP solutions should be Extracted & retained for 60 days.

when the script is run it creates a dynamic folder based on date & retain it for 60 days (or the days you define)

Extract the ZIP file from below link, Define the Variables in .ps1 file :(shown in bold) $dir(path for backup) & $limit (retention)

Run or schedule the batch file.

https://gallery.technet.microsoft.com/scriptcenter/SharePoint-WSP-Solutions-2c3f922e

###################Define Variables#####################
$Dname = ((get-date).AddDays(0).toString(‘yyyyMMdd’))

$dirName = “WSPBackup_$Dname”

$dir= “E:\Scripts\SharepointBackup\backup\WSP”

$limit = (Get-Date).AddDays(-60)

###################################################

################################################################################## 
#            Author: Manhur Mannan 
#            Reviewer: Vikas Sukhija 
#            Date: 03/07/2015 
#            Description: Take WSP Backups & retention 
################################################################################## 
#############################ADD SHell############################################ 
If ((Get-PSSnapin | where {$_.Name -match "Microsoft.SharePoint"}) -eq $null) 
{ 
    Add-PSSnapin Microsoft.SharePoint.PowerShell 
} 
 
###################Define Variables##################### 
 
$Dname = ((get-date).AddDays(0).toString('yyyyMMdd'))  
$dirName = "WSPBackup_$Dname" 
$dir"E:\Scripts\SharepointBackup\backup\WSP" 
$limit = (Get-Date).AddDays(-60) 
 
 
#####################Solution Extraction################# 
 
new-item -path $dir -name $dirName -type directory 
 
 
Write-Host Exporting solutions to $dirName  
 
 
foreach ($solution in Get-SPSolution)  
{  
    $id = $Solution.SolutionID  
    $title = $Solution.Name  
    $filename = $Solution.SolutionFile.Name 
    Write-Host "Exporting ‘$title’ to …\$filename" -nonewline  
    try {  
        $solution.SolutionFile.SaveAs("$dir\$dirName\$filename")  
        Write-Host " – done" -foreground green  
    }  
    catch  
    {  
        Write-Host " – error : $_" -foreground red  
    }  
} 
  
##########################Retention########################## 
$path = $dir 
 
Get-ChildItem -Path $path  | Where-Object {  
$_.CreationTime -lt $limit } | Remove-Item -recurse -Force 
 
##############################################################

Regards

Sukhija Vikas

http://msexchange.me

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s