Solved

Sharepoint automated backups via Powershell

Posted on 2012-03-29
7
701 Views
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
2.
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
   dPSSnapinCommand\

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.
0
Comment
Question by:ded2545
  • 4
  • 3
7 Comments
 
LVL 38

Expert Comment

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

Author Comment

by:ded2545
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.
0
 
LVL 38

Expert Comment

by:Justin Smith
ID: 37783176
Waiting for that screen....
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
LVL 1

Author Comment

by:ded2545
ID: 37783185
Sorry about that...
sharepoint-task.JPG
0
 
LVL 38

Expert Comment

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

Accepted Solution

by:
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.
0
 
LVL 1

Author Comment

by:ded2545
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!
0

Featured Post

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!

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
A procedure for exporting installed hotfix details of remote computers using powershell
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 …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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