I had to write a quick script for backing up a SharePoint farm and didn't want to write two separate scripts to accomplish essentially the same thing. So I just added a little PowerShell script to change the backup type based on the day of the week. So we run full backups on Sundays and differential backups during the week. Nothing magical and I thought I would share the script love.
# Standard Load of the SharePoint plugin for PowerShell, nothing special here
$snapin
= (Get-PSSnapin
-name
Microsoft.SharePoint.PowerShell -EA SilentlyContinue)
IF ($snapin
-ne
$null){write-host
"SharePoint Snap-in is loaded"}
ELSE { write-host
"SharePoint Snap-in not found... Loading now"
Add-PSSnapin
Microsoft.SharePoint.PowerShell
write-host
"SharePoint Snap-in is loaded"
}
# END Loading SharePoint Snapin
# Lets get the day of the week using the DateTime object
([system.datetime]$date
= $([system.datetime]::now))
$dayofweek
=
$date.DayOfWeek
#set the location where you want to backup the farm
$backupDirectory
=
"\\server\folder\subfolder"
#If its Sunday let's do a full backup instead of a differental
if($dayofweek
-eq
"Sunday")
{
write-host
"$dayofweek - Full Backup being Executed"
Backup-SPFarm
-Directory
$backupDirectory
-BackupMethod
Full
}
else
{
#Its not Sunday, so let's just do a differential backup
Write-Host
"$dayofweek - Differential Backup Being Executed"
Backup-SPFarm
-Directory
$backupDirectory
-BackupMethod
Differential
}