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....
Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations


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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Suggested Solutions

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…

734 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