Sharepoint automated backups via Powershell

Posted on 2012-03-29
Last Modified: 2012-03-29
I'm having a very strange issue.  I am in the process of creating scripts to automate my backups in SharePoint 2010.  My scripts work, I've ran them manually and it completes my backups.  The problem I'm having is that they're failing when they're called via task scheduler.  I can run power shell, open my ps1 file and run it, works great.  But the issue is when it calls power shell via task scheduler, it says it can't add the snap in  Error here:

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
At line:1 char:13
+ add-pssnapin <<<<  microsoft.sharepoint.powershell
    + CategoryInfo          : InvalidArgument: (microsoft.sharepoint.powershel
   l:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad

This makes absolutely ZERO sense considering I can navigate to the system 32 folder, and manually open power shell, and add this snap in successfully.  In task scheduler I have it opening a the powershell.exe from the exact same path in the system 32 folder.

So I tested it, and had it open power shell with the no exit option, and tried manually adding the snap in, it fails.  I'm not sure if it's getting confused because of permissions or what, but it's driving me crazy.

Also have the execution policy set to unrestricted.

A side note, if you're going to answer this, do not go to google and post any links that are within the first 5 results...because I've looked there.
Question by:ded2545
  • 4
  • 3
LVL 38

Expert Comment

by:Justin Smith
ID: 37783029
How are you calling the script from the task?

Author Comment

ID: 37783117
I'm attaching a screen shot of what I have in task scheduler.  Keep in mind, it's a 3rd party task scheduler.  Which shouldn't make a difference, does the same thing in windows task scheduler.
LVL 38

Expert Comment

by:Justin Smith
ID: 37783176
Waiting for that screen....
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline


Author Comment

ID: 37783185
Sorry about that...
LVL 38

Expert Comment

by:Justin Smith
ID: 37783277
No .ps1 at the end of the file?
LVL 38

Accepted Solution

Justin Smith earned 305 total points
ID: 37783300
Typically when I call them, I do it through a batch file.  Create the batch file with....

powershell -command "& 'ScriptName.ps1' "

Then run the batch from the task.

Author Comment

ID: 37783364
The batch file seems to be working, thanks!  Big fail on the MS book on automating this I guess!  Their way doesn't seem to work AT all!

Featured Post

Too many email signature changes to deal with?

Are you constantly being asked to update your organization's email signatures? Do they take up too much of your time? Wouldn't you love to be able to manage all signatures from one central location, easily design them and deploy them quickly to users. Well, you can!

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
OfficeMate Freezes on login or does not load after login credentials are input.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This tutorial will walk an individual through the steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now