5

I am trying to run a startup task cmd-script on a Windows Azure Role.

This are the two lines of the command file script:

powershell $command = "set-executionpolicy Unrestricted"    
powershell $command = ".\setupAgent.ps1" -NonInteractive >; out.txt

Now the problem is, I get an error message from the command shell, that says:

D:\Users\UserAccount>powershell $command = "set-executionpolicy Unrestricted"
'powershell' is not recognized as an internal or external command,
operable program or batch file.

It looks like there are used some kind of different codepages or something linke that, because these special chars are not in my cmd file. The cmd-file was created on Windows 8 via VS 2012 Ultimate.

Do you have an idea, how I can dismiss there special chars at the beginning of the command? If I copy the command from the cmd-file to the console via remote desktop it works fine!

sebastian87
  • 454
  • 4
  • 15

1 Answers1

8

Open your whatever.cmd file with your VS 2012 Ultimate. Click on File->Save whatever.cmd as -> on the dialog there is little arrow next to the [save] button. It will show up a menu that will have the option Save with Encoding:

Save With Encoding

Select it. Now choose "US-ASCII Codepage 20127" from the list of available encodings.

astaykov
  • 30,768
  • 3
  • 70
  • 86
  • Thanks, that was the solution! – sebastian87 Apr 11 '13 at 13:12
  • +1. Can you elaborate on why this encoding is needed? – Lasse Christiansen Nov 14 '14 at 18:52
  • 4
    Visual Studio by default save files in UTF-8 with BOM (Byte Order Mark - The first bytes of the file). OSes, including Windows does not recognize this when executing `script` files. This causes any script file, that is saved in UTF-8 with BOM to fail. General Rule of thumb is, script files (DOS Batch files, PS files, BASCH scripts, Peral, PHP, etc.) that are to be executed by the OS, to have native ASCII Encoding. – astaykov Nov 14 '14 at 21:09