SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Powershell execution error


Powershell execution error

Author
Message
kstjacques
kstjacques
SSC Veteran
SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)SSC Veteran (215 reputation)

Group: General Forum Members
Points: 215 Visits: 376
Greetings,

I have a script that was executing a powershell script from within a batch file with the following syntax:
"“powershell.exe -NoLogo -Noninteractive -Command "& \"%~dp0ScriptName.ps1\" %1; exit "

Everything was working fine until the OS team patched the server and upgraded Powershell to version 3 (it had version 2). After Powershell was upgraded the script failed with the error:

"powershell.exe' is not recognized as an internal or external command, operable program or batch file"

For the time being I have "fixed" the issue by executing powershell with an explicit path:
"C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Noninteractive -Command "& \"%~dp0ScriptName.ps1\" %1; exit"

Now, this change may make my script functional again, but I don't understand what exactly is going on. What changed when Powershell was upgraded that made the way I was calling the script invalid?

Any information or good links to information would be greatly appreciated.

Thanks!
Kim
Orlando Colamatteo
Orlando Colamatteo
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41530 Visits: 14413
Chances are the path "%systemroot%\System32\WindowsPowerShell\v1.0\" was removed from the PATH system environment variable. Removing the path to powershell.exe from the PATH variable made it impossible for you to refer to powershell.exe from any random command line location without fully qualifying it.

As a side note the explicit path you decided to prefix your command with, "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\", is the path to the 32-bit version of powershell.exe on 64-bit OS'es. Prior to the upgrade it is likely you were executing your script using the 64-bit version. Chances are it is not making a difference since you said the script is working but I thought it was worth pointing out.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search