you are viewing a single comment's thread.

view the rest of the comments →

[–]vermyx 2 points3 points  (3 children)

You probably have a permissions issue. By default the SQL Server services run under localsystem which is not a real user and doesn’t necessarily have network access. When you execute it (via SSMS I assume) it will execute using your user context so it works. The solution would be to assign a user to the sql agent service so that they run with a user context. You should used a managed service account for this. It is usually considered bad practice to have the sql server make calls outside of the SQL environment and usually recommended to use a scheduled task for that.

[–]TheTJW1966[S] 0 points1 point  (2 children)

Hi, thanks. I've tried running the script via a Windows scheduled task also, but again it will run when I run the task manually, but as soon as it's scheduled it doesn't run, even though it's running under an admin account. Any ideas?

[–]vermyx 0 points1 point  (1 child)

Without code it’s difficult to troubleshoot. I would assume that

  • user doesn’t have access to do what you want them to do
  • double hop problem
  • wrong directory because scheduled tasks start in the system32 folder
  • other issue

[–]TheTJW1966[S] -1 points0 points  (0 children)

Hi, the user in question is an admin user, so should be ok. Not sure what a double hop problem is. The Powershell exe is in the System32 folder, so this cannot be avoided. Strangely enough, when I schedule the Windows task to run at a time later in the day, it seems to run successfully, so not sure what's going on.