Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Problem running a powershell script

I have a very simple powershell script (only 2 lines) as two lines indicated below

cls
$Folder = “C:\Temp1\\Temp2

But I get errors when I run it inside Administrator Power Shell as indicates the line below

c:\Temp1\a,ps1


Can anyone tell me what do I do wrong?  Thanks
Capture.JPG
Capture2.JPG
0
tommym121
Asked:
tommym121
  • 4
  • 3
  • 3
2 Solutions
 
Ram BalachandranCommented:
Interesting,  “C:\Temp1\\Temp2” is just a value set in $Folder.

Are you getting any error when you execute this line directly from powershell window ?
0
 
tommym121Author Commented:
NO
0
 
Ram BalachandranCommented:
how you are executing the powershell script  ?
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
DontmilkthisCommented:
It looks like you're using some special characters that are normally used in Word to make things look pretty.

for example those quotation marks aren't true quotation marks.

not sure what the A characters are in the output, but i'd suggest manually typing out the powershell script again in notepad or a normal text editor

"normal quotes"
“quotes copied from your example”

if you look really close, you can see the difference
0
 
tommym121Author Commented:
Dontmilkthis,

Thanks for your help.  I think when copy the code from the web page, I might have copy some hidden character(s) that cause the problem. When I retype it, i have no problem.
0
 
tommym121Author Commented:
Thanks for your help
0
 
DontmilkthisCommented:
Yeah it's a bit of a pain when copying from a website, Word doco or email that does some replacement of normal expected characters with characters from the extended set simply for cosmetic effect.

things to look out for mostly are quotation marks, apostrophes and hyphens/dashes.
these are the most common ones I've found.

Glad I could help
0
 
Ram BalachandranCommented:
Best practice is to copy the code from website to a notepad, and from there copy to editor.
0
 
DontmilkthisCommented:
I find notepad is still capable of maintaining the extended set characters, at least in windows 7, I don't recall about previous versions.
0
 
tommym121Author Commented:
ram_kerala

I did copy to the notepad and save it. Now I know I have to pay more attention to the code on internet.  Thanks.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now