0

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:

enter image description here

I believe that this organization is on the same versions of SQL, Powershell, and Windows as the organizations 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?

Jakub Kriz
  • 1,501
  • 2
  • 21
  • 29
  • Stating the obvious, but I'm guessing that the version of PS or .net is missing the `Locked` property from whatever type you're using. What does `$PSVersionTable` show? What type is it? Also have you checked the usual suspects, `PATH`, perms etc? – Liesel Apr 06 '16 at 02:57
  • Thanks @Les H. Wouldn't the fact that the script runs successfully when executed within a PS window indicate that the Locked property is not missing? It's only when the script is executed via xp_cmdshell that it fails. Here's the script that is failing: $doc.Fields.Locked = -1. You mention "perms". I'm suspecting that this is permissions-related. Any suggestions on permissions issues that might affect this? – Brian Davies Apr 11 '16 at 23:52
  • What type is `$doc.Fields` ? What does `sys.xp_cmdshell 'powershell.exe -c "$PSVersionTable"'` show compared to `$PSVersionTable` in an interactive powershell? Which version of SQL server and OS are you running? Again, sorry if this isn't much use, I'm guessing in the dark here. – Liesel Apr 12 '16 at 05:12

0 Answers0