locked
PowerShell Script working manually but not through Scheduled Task RRS feed

  • Question

  • Hi,

       I have a 2 server farm with Web Front end on one server and Database on other. I am trying to schedule a daily farm backup by creating a powershell script. I create a new task in Windows Task Scheduler and call the ps1 file from a .bat file. When i run the .bat file manually the backup is successful but when I schedule the task to run automatically it does not create any backup and gives me the error "Object reference not set to instance of an object".

     

    Similarly I have created a ps1 file which will run the Update-SPProfilePhotostore command each night. This ps1 executes manually but when executing automatically it gives the error "Cannot find an SPSite object with Id or Url: " for the mysitehostlocation url i have given. I have checked that the mysitehostlocation URl is correct.

    Please guide me on this problem.

     

     

    Monday, January 16, 2012 11:21 AM

Answers

  • Could the problem be because I select the option "Run the task whether user is logged in or not" and check the "Do not store password" option. Due this it is not able to access the DB(which is on other server)?


    This problem is solved. Windows Server 2008 has a problem that when you select the option  "Run the task whether user is logged in or not" and do not check  "Do not store password" option it locks out the user id. Due to this I used to check the "Do not store password" option which was causing the problem. Microsoft has a hotfix for this Windows Server 2008 problem. I installed the hotfix and again created the scheduled task this time with "Do not store password"  unchecked. My scripts are working fine now.

     

    • Marked as answer by SPHOW Monday, February 6, 2012 12:49 PM
    Monday, February 6, 2012 12:49 PM

All replies

  • make sure to specify an identity (in security options) for the scheduled task that have permission on the site
    Monday, January 16, 2012 12:03 PM
  • or in task properties window in general tab check "Run with highest privileges"
    Monday, January 16, 2012 12:08 PM
  • You need to run the scheduled job as an identity and the identity you are running the job as should be setup following the SP Powershell directions here: http://technet.microsoft.com/en-us/library/ee806878.aspx

     

    You can manually go in an add the security role to the machine account which will enable local/network service which the job will run as but I don't think this is a reccomened setting.  I would create a service account for running power shell scripts as a scheduled job and give it the appropriate permissions.

     

    Monday, January 16, 2012 2:39 PM
  • Hi, I have specified "Run with highest privileges".
    Tuesday, January 17, 2012 3:12 PM
  • Could the problem be because I select the option "Run the task whether user is logged in or not" and check the "Do not store password" option. Due this it is not able to access the DB(which is on other server)?
    Tuesday, January 17, 2012 3:14 PM
  • Could the problem be because I select the option "Run the task whether user is logged in or not" and check the "Do not store password" option. Due this it is not able to access the DB(which is on other server)?


    This problem is solved. Windows Server 2008 has a problem that when you select the option  "Run the task whether user is logged in or not" and do not check  "Do not store password" option it locks out the user id. Due to this I used to check the "Do not store password" option which was causing the problem. Microsoft has a hotfix for this Windows Server 2008 problem. I installed the hotfix and again created the scheduled task this time with "Do not store password"  unchecked. My scripts are working fine now.

     

    • Marked as answer by SPHOW Monday, February 6, 2012 12:49 PM
    Monday, February 6, 2012 12:49 PM
  • Do you have the hotfix number for this.  I am having the same exact issue with Powershell scripts.  I can't check "Do no store password" since these scripts are accessing network resources.


    http://techwithmike.com

    Tuesday, September 3, 2013 2:52 PM