Backup-SPFarm do not run in scheduler in batch mode - option "run whether user is logged on or not"


  • I did everything according to instructions and script works interactively. It makes backup without errors.

    Then I putted this script into Windows scheduler. Here are my problems began. Script works only when I run it in scheduler with option "run only when users is logged on". (of course option "run with highest privileges" is ON) When I changed option to "run whether user is logged on or not" script failed. User was the same. Message was:

    Backup-SPFarm : You need to have Machine administrator priviliges to run this cmdlet.
    At \\serversql\back\task\BackupSharepointFarm.ps1:2 char:14
    + Backup-SPFarm <<<<  -Directory \\serversql\back\Backup -BackupMethod full -Verbose
        + CategoryInfo          : InvalidData: (Microsoft.Share...mdletBackupFarm:SPCmdletBackupFarm) [Backup-SPFarm], SPException
        + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletBackupFarm

    Here is my script BackupSharepointFarm.ps1:

    Add-PSSnapin Microsoft.SharePoint.PowerShell
    Backup-SPFarm -Directory \\serversql\back\Backup -BackupMethod full -Verbose

    The farm has two servers:
    1. sharepoint server , 2. sql server

    Backup task is of course scheduled on sharepoint server.
    Shared disk for backup is on sql server (separate, dedicated disk). All required users have full or write/modify access to disk & share. As I mentioned script works fine when run interactively.
    What could be the reason for the error?

    Please help me ! I spent plenty of time for testing and searching for clues in the network .


    Thursday, December 30, 2010 6:45 AM

All replies

  • The reason is that Powershell is searching for a Profile when using Powershell. So when it has no profile to load, it will fail.

    You can try to load pre-load a profile. So you'll hit a bat file which loads a profile, and then start the powershell script.


    • Marked as answer by Lily Wu Thursday, January 06, 2011 2:24 PM
    • Unmarked as answer by pavko_x Tuesday, January 18, 2011 3:05 PM
    Thursday, December 30, 2010 9:03 AM
  • Thanks for quick suggestion. I will check it and answer how it works.
    Best Regards

    Thursday, December 30, 2010 3:14 PM
  • Could you please explain me the best way to load profile in batch script? I thought it is enough to run task in scheduler using domain user, with option "run whether user is logged on or not" and it should load user profile. But it doesn't work in my issue. I asked Google, but didn't find any interesting information about loading profile in batch file. Have you got any suggestion?
    Thursday, January 13, 2011 2:09 PM
  • I suppose nobody who red this question had the similar problem. Maybe it should work. I have no idea what should I check.
    Tuesday, January 18, 2011 3:03 PM
  • Hi,

    when running the option "run whether user is logged on or not" is not the solution, because it doesn't load the profile. It's running in another context, so the profile isn't loaded.

    You can use the following command as example:

    runas /profile /env /user:mydomain\admin "mmc %windir%\system32\dsa.msc"


    Tuesday, January 18, 2011 3:18 PM
  • You should be able to get this to work with "Run whether user is logged on or not" if you specify for the task to save the user password.

    Wednesday, April 27, 2011 7:56 PM
  • In my case it didn't untill I logged in to the box as user that sheduled task is run under.

    The first time you login windows creates user profile on the machine and I guess that was the case.

    After that, as mentioned above:

    1. Login to the box at leas once using user from Sheduled Task

    2. powershell -Command c:\Scripts\Backup_sharePoint_Full.ps1

    3. "Run whether the user is logged or not" and "Do not store password"

    4. "Run with highest privileges"

    5. RW access to the backup path granted for Central Admin App pool user, SQL Service user, user you run sheduled task under.


    Works like a char.

    Thanks guys.

    Thursday, November 03, 2011 11:37 AM