question

Gloops-5441 avatar image
0 Votes"
Gloops-5441 asked ·

This is the title : "REM not recognized as a command"

Hello everybody,

In a Powershell script, I have this :

<#
# # # # # # rem Copy-Item -Path Y:\web\$N $path;
#
#
#>


and at compilation it yells that Rem is not recognized as a command. Well, does this mean that rem is code and not a comment ? How can I solve this ?


My first attempt was just like this :

# rem Copy-Item -Path Y:\web\$N $path;




I have no clue why it appears bold, but at least like that it is clear, as I made three iterations to make the character appear rather than being interpreted as bold.



windows-server-powershell
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I just pasted your example into a PowerShell prompt and, as expected, nothing happened.

I did the same at a CMD.exe prompt and got this:

 C:\Users\richm><#
 The syntax of the command is incorrect.
    
 C:\Users\richm># # # # # # rem Copy-Item -Path Y:\web\$N $path;
 '#' is not recognized as an internal or external command,
 operable program or batch file.
    
 C:\Users\richm>#
 '#' is not recognized as an internal or external command,
 operable program or batch file.
    
 C:\Users\richm>#
 '#' is not recognized as an internal or external command,
 operable program or batch file.
    
 C:\Users\richm>#>

So . . . you'll have to provide more detail and context.

0 Votes 0 ·

The issue cannot be reproduced on my side. How did you run the script?

0 Votes 0 ·
AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered ·

You are talking about PowerShell?
In PowerShell the # is for comments (one line or in the middle of a line).

If you like to have more lines in a row as a comment use <# at the beginning and #> at the end.


 # Some examples
 Get-Help # this is a comment following a cmdlet
    
 <#
 This a block where you can comment in lines.
 Just as an example
 #>


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten


· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Gloops-5441 avatar image
0 Votes"
Gloops-5441 answered ·

Well, as you see, this is exactly what I did.
But in both cases, REM seems to be refused in a REMARK.

· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Gloops-5441 ,

and your are running your script in PowerShell?

Never noticed # is not working in PowerShell.


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·
Gloops-5441 avatar image
0 Votes"
Gloops-5441 answered ·

Hum, it seems it works so long you do not have "REM" in the comment.

· 1 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Here no problem ... even with REM

 get-help
 # REM copy-item whatever
 Get-Host

No error, warning or something else on line 3


(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

Regards
Andreas Baumgarten

0 Votes 0 ·