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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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....
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will show how to push an installation of Backup Exec to an additional server in both 2012 and 2014 versions of the software. Click on the Backup Exec button in the upper left corner. From here, select Installation and Licensing, then I…
In a recent question ( here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

623 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