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 ##############################################################
Tech Wizard