1

I have a Powershell script called MSSQLStartStopServices.ps1 used to stop some SQL Server services. This script is being called using a third-party vendor software. The parameters in question are Fully qualified instance name and Start|Stop

e.g.

MSSQLStartStopServices.ps1 HOSTNAME\INSTANCENAME Start

For a default instance, the software passes (local) as the INSTANCENAME.

MSSQLStartStopServices.ps1 HOSTNAME\(local) Start

But when I run this I get an error from Powershell:

The term 'local' 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.

When I try and put the instance name in quotes it works fine in a Powershell window:

MSSQLStartStopServices.ps1 "HOSTNAME\(local)" Start

However the third party software calls Powershell from the commandline first, like so:

powershell .\MSSQLStartStopServices.ps1 "HOSTNAME\(local)" Start

This causes the same error as if the quotes were not there.

How do I work around this issue?

2
  • Surround all your command and params with quotes powershell ".\MSSQLStartStopServices.ps1 HOSTNAME(local) Start" Commented Jun 19, 2013 at 11:31
  • typo Surround all your command and params with quotes powershell ".\MSSQLStartStopServices.ps1 'HOSTNAME(local)' Start Commented Jun 19, 2013 at 12:02

2 Answers 2

7

Try enclosing your script-call in double quotes and then each parameter in single quotes:

".\MSSQLStartStopServices.ps1" 'HOSTNAME\(local)' 'Start'
Sign up to request clarification or add additional context in comments.

Comments

0

Adding this information for any future people with a smiliar issue finding this page:

In case you want to use a variable as a parameter value that contains characters such as "(" or "|", you need to do it like this: -parameter_name ("'" + $variable + "'")

This worked for me since powershell would remove any double quotes added to the string when calling a non powershell method.

Comments

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.