1

I want to execute a powershell script within microsoft management studio. But I get an error. Look below for more details:

EXEC master..xp_cmdshell '%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -command "C:\tmp_es\test.ps1"'

C:\tmp_es\test.ps1 : The term 'C:\tmp_es\test.ps1' is not recognized as the 
name of a cmdlet, function, script file, or operable program. Check the 
spelling of the name, or if a path was included, verify that the path is 
correct and try again.
5
  • It's probably because the SQL process doesn't have access to C:\tmp_es Try changing the permission on tmp_es to read all users. Commented Jun 20, 2016 at 12:14
  • I think you are right. But now I must know what the name is of the sql management studio server. Do you maybe know? Commented Jun 20, 2016 at 12:21
  • Are you running Sql Server on the same machine as Management Studio, or on a remote server? Commented Jun 20, 2016 at 12:31
  • Yeah. It is running on the same machine. So what can I do ? Commented Jun 20, 2016 at 12:50
  • It was indeed the wrong path. Now I've inserted the good path and it is working now. Thanks Commented Jun 20, 2016 at 13:34

1 Answer 1

1

Change the -Command to -File

EXEC master..xp_cmdshell '%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -File "C:\tmp_es\test.ps1"'
Sign up to request clarification or add additional context in comments.

1 Comment

this doesn't work. I think indeed it has no permission to that folder sql management studio.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.