# Sharepoint Farm backup via Scheduled Task

• ### Question

• So I've been slamming my head against a wall for a few hours now.  Basically I created a powershell script called fullfarmbackup.ps1 and this is the contents of it:

try
{
$today = (Get-Date -Format dd-MM-yyyy) #Location of the Backup Folder [IO.Directory]::CreateDirectory("C:\SharepointBackup\$today")
# This will actually initiate the SPFarm backup.
Backup-SPFarm -Directory C:\SharepointBackup\\$today -BackupMethod full

}

The script runs just fine when I run it manually from Sharepoint 2010 Management shell.  So my questions is how do I put this into scheduled task so that I can have it run on a set schedule.  I've tried everything and it will not work.  The issue is the path to Sharepoint 2010 Management shell is C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -Version 2.0 -NoExit  " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' "

I've tried time and time again to run that command with it pointing to my script and it will not run.  Any ideas?

Thursday, May 23, 2013 6:20 PM

• FYI you should always use the same folder for SharePoint backups so it can properly record the history to the spbrtoc.xml file.

As for the task, you need to run it as a user that has Local Admin rights on the SharePoint server(s) in addition to being a Farm Administrator.  You should also set it to "Run with highest privileges".  As for execution, run:

powershell.exe -command "C:\path\to\backupscript.ps1"

SharePoint - Nauplius Applications
Microsoft SharePoint Server MVP

-----------------------
This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

Thursday, May 23, 2013 6:51 PM
• Finally got it, had a brainfart.  I have a GPO that restricts who can run batch jobs (and I knew this) so I was running the scheduled tasks as a user who had that permission.  Issue was that I was logged in as a local admin (someone who doesn't have the ability to run batch jobs) and I forgot to check the checkmark to Run job even if this user isn't logged in.  Checked that and it works fine now.
• Proposed as answer by Thursday, May 23, 2013 8:16 PM
• Marked as answer by Friday, May 24, 2013 12:40 AM
Thursday, May 23, 2013 7:12 PM

### All replies

• FYI you should always use the same folder for SharePoint backups so it can properly record the history to the spbrtoc.xml file.

As for the task, you need to run it as a user that has Local Admin rights on the SharePoint server(s) in addition to being a Farm Administrator.  You should also set it to "Run with highest privileges".  As for execution, run:

powershell.exe -command "C:\path\to\backupscript.ps1"

SharePoint - Nauplius Applications
Microsoft SharePoint Server MVP