0

I am passing a directory into a powershell script. I have done this before, but apparently I haven't done it with a directory that has spaces in it: For example...

C:\Program Files (x86)\Microsoft SDks\Windows\v7.0A\bin\

Well, simple enough right, just surround it with paren's right? Wrong... When it is in my actual script it is throwing the following anoying exception:

The term 'x86' 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 include
d, verify that the path is correct and try again.
At line:1 char:275

This is being passed into my script as a parameter btw, hence why it is throwing the error at line 1.

Any advice on passing directories as paramters into powershell scripts?

5
  • What are you passing it from? Batch file? C#? ASP? Java? Commented May 12, 2014 at 21:07
  • just the command line. I have control over what I send in. Commented May 12, 2014 at 21:11
  • 2
    Can you give us the first line of the script? The issue may not be with the passing of the folder but with the way the script is handling it. Though seeing as it is at character 275, that's a little frightening. Commented May 12, 2014 at 21:25
  • You need to say exactly how you're calling this PowerShell script. Typing it at the PowerShell command line? From a shell script (batch file)? Task scheduler? Commented May 12, 2014 at 22:23
  • Sorry, I literally open up a command line and input the string. Turns out that it was the way I calling the string in my script. Thanks for the assist. Commented May 14, 2014 at 12:47

1 Answer 1

1

Try putting into into quotes, single or double will work.

You can also throw it into a variable first.

Sign up to request clarification or add additional context in comments.

1 Comment

tried single and double quotes and a combination of both. I still get that exception.

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.