question

buraien avatar image
buraien asked

Executing powershell from xp_cmdshell

I have a powershell file that looks to a directory and locks the fields on each of the Word documents that are contained in that directory. I am executing this powershell file from a SQL stored procedure using xp_cmdshell. I have implemented this solution at several organizations without a problem. I am currently implementing this at another organization, but am having problems. At this new organization, if I execute the powershell file manually from within a Powershell window, the script runs successfully and locks the fields on each of the documents. However, when the same PS file is attempted to be run from the SQL stored procedure via xp_cmdshell, I am getting the following error message: ![alt text][1] I believe that this organization is on the same versions of SQL, Powershell, and Windows as the organization where this does work successfully. I'm suspecting that this might be some sort of permissions or SQL configuration issue but am at a loss at this point. Any ideas? [1]: /storage/temp/3314-capture.jpg
powershellxp_cmdshell
capture.jpg (28.6 KiB)
5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What does `SQL Configuration` have anything to do with files in a folder? If a property comes back as not exists then it generally does not in PS, you should verify the commands you are using work in the current version on the server.
2 Likes 2 ·
Could you post the code that set the lock on the files?
0 Likes 0 ·
What @Shawn_Melton said. Also, check the permissions on the SQL Server service account are sufficient for doing this sort of thing.
0 Likes 0 ·
If the script works as desired when running it via a PS window, I assume that the property exists. It's only when the PS script is run via xp_cmdshell does it not work. We've checked the permissions on the SQL Server service account as well, and all seems fine there.
0 Likes 0 ·
So go into cmd prompt and call your script the same way...you will likely see the same issue. However we can't do much for you unless you are plan on posting the code.
0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.