Blog Image

PowerShell

SharePoint Powershell Commands

GoSharePoint Website
Documentation Blog

This blog is based on SharePoint 2013 PowerShell Commands. Please visit my other blog which contains SharePoint Documentation.

Restore from backup

Backup / Restore Posted on Tue, June 28, 2016 04:43:26

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

# Allow execution of scripts

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force

Write-Host “Restoring site from backup”

restore-SPSite http://spsite/ -Path “c:\temp\spbackup.dat” -force -confirm

Write-Host -f Green “Completed site from backup”



Performs a Full or Differential backup of the local computer and emails user on completion

Backup / Restore Posted on Mon, June 27, 2016 17:16:39

<#====================================================================

Copyright © 2016, June. Michael Pomfret

Performs a Full or Differential backup of the local computer and emails user on completion.

1. Script set to complete a full backup on Sunday.

2. Script set to complete a Differential backup on every day excepy Sunday.

====================================================================#>

Set-ExecutionPolicy -ExecutionPolicy “Unrestricted” -Force

Add-PSSnapin “Microsoft.SharePoint.PowerShell”

$ScriptStart = (Get-Date)

$strToday = “Universal Time: ” + $ScriptStart.ToUniversalTime()

$ThisComputer = $env:COMPUTERNAME

$backupDir = “<Drive>:\SharePoint\Backup\” + $ThisComputer

$strToday = (Get-Date).ToString(‘dd-MM-yyyy’)

if((get-date).DayofWeek -eq “Sunday”)

{

$subject = “Task Scheduler: Full Weekly Backup Scheduled for ” + $ThisComputer + ” ” + $strToday

$BackupType = “Full”

Backup-SPFarm -BackupMethod Full -Directory $backupDir

}

else

{

$subject = “Task Scheduler: Daily Backup Scheduled for ” + $ThisComputer + ” ” + $strToday

$BackupType = “Differential”

Backup-SPFarm -BackupMethod Differential -Directory $backupDir

}

$ScriptEnd = (Get-Date)

$RunTime = New-Timespan -Start $ScriptStart -End $ScriptEnd

$smtp = “courier.cf.ac.uk”

$to = “pomfretml@domain.com”

$from = “SharePoint@”+$ThisComputer+”.cf.ac.uk”

$body = “The ” + $BackupType + ” backup has completed for ” + $ThisComputer

$body += ” <br>”

$body += ” <br>”

$body += “Location of Backup ” + $backupDir

$body += ” <br>”

$body += ” <br>”

$body += “Time to complete: {0}:{1}:{2}” -f $RunTime.Hours,$Runtime.Minutes,$RunTime.Seconds

#### Now send the email using > Send-MailMessage

send-MailMessage -SmtpServer $smtp -To $to -From $from -Subject $subject -Body $body -BodyAsHtml -Priority high