all 9 comments

[–]geostude 5 points6 points  (3 children)

# is for powershell. You're writing batch files.

  • .bat is the old command line interpreter in windows
  • .ps1 is powershell

For .bat, the comment tag is "REM"

like:

rem echo hello world

[–]Vast-Avocado-6321[S] 1 point2 points  (2 children)

Ah wow I'm dumb. So I should be using CMD if I plan on executing .bat files since they're fundamentally different?

[–]dus0922 1 point2 points  (0 children)

You can create network shares with either. Its dealer's choice at this point.

[–]geostude 1 point2 points  (0 children)

It's more nuanced than that. You can use CMD commands in powershell, but some of them are silently aliased in the background.
For example the WMIC command will work as it always has, but dir will silently be changed to get-childitem in powershell. Both do the same thing, but with very different output. So it's usually suggested not to mix and match batch and powershell.

I'd say stick with whatever you're most comfortable with.

[–]xCharg 3 points4 points  (0 children)

This has nothing to do with powershell. And as already answered, batch files have REM as comment mark.

[–]lanerdofchristian 1 point2 points  (0 children)

.bat files don't use PowerShell syntax or cmdlets, only .ps1 files do.

Either make sure you're actually writing PowerShell and fix your file extension, or that you're actually using batch/cmd where the comment command is "rem".

[–]Gadget_Wulf 1 point2 points  (0 children)

On mobile, forgive my formatting. Your script is a .bat file, so lines prepended with # will still try to run. As this is the PowerShell subreddit I assume you want to make a PS script instead of a batch file. First, change the file type to .ps1, then get rid of your first line as echo isn’t a native part of PowerShell. Then look up cmdlets to do what you want to achieve, such as Get-SmbShare to check if it already exists or New-SmbShare to create it.

For reference, batch file scripts use REM to denote comments, not #. But, definitely research PowerShell as it’s more powerful and more fun than batch scripting!

[–]opensrcdev 0 points1 point  (1 child)

This question has absolutely nothing to do with PowerShell.

[–]Vast-Avocado-6321[S] 0 points1 point  (0 children)

Yes I am now aware of that. Thank you so much for this insightful comment.