I'm trying to execute a powershell script, and use a proxy to do. The job runs correctly, but using whoami within the script to log the executing user indicates that the script is not being run by the user I (think I) specified in the proxy.

I have a credential, with the correct username and password for the windows server:


I have a proxy set up to use that credential:


The user [Domain]\MSSQLService02:

  • Is specified as a principle for this proxy

  • Has its own login

  • Is the job owner

I'm using the proxy to Run As in the job step:

Run as

However, as mentioned, logging within the script indicates that [Domain]\MSSQLService02 is the user executing the script.

I don't know if I'm misunderstanding the use of proxies, I'm missing a step, or something is misconfigured.

  • 1
    Can you explain why it's necessary to involve SQL Server in this? My initial answer to this kind of problem will always be to kick off this Powershell script from Windows, not from SQL Server. Nov 7, 2018 at 19:19
  • The PS script depends on a few things to happen in the DB prior to running. Nov 7, 2018 at 19:39
  • 1
    So why can't Powershell call the things in the database instead of the opposite? Nov 7, 2018 at 19:41
  • I can see a number of instances where being able to call a PowerShell script from SQL Agent would be helpful. I'm running into the same issue as @NateAnderson due to the use of $home in the powershell script, and it referencing the service account running Sql Agent, instead of the Proxy I setup for the job. Nov 25, 2018 at 1:20


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.