From How to run a PowerShell script within a Windows batch file
There's an idiom in CMD scripts to use ::
as a comment delimiter. (:
means a label, so ::
gets ignored.) I use it because I think it's easier to read than REM
.
I wrote this in an answer:
@@:: This prolog allows a PowerShell script to be embedded in a .CMD file.
@@:: Any non-PowerShell content must be preceeded by "@@"
@@setlocal
@@set POWERSHELL_BAT_ARGS=%*
@@if defined POWERSHELL_BAT_ARGS set POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%
@@PowerShell -Command Invoke-Expression $('$args=@(^&{$args} %POWERSHELL_BAT_ARGS%);'+[String]::Join(';',$((Get-Content '%~f0') -notmatch '^^@@'))) & goto :EOF
which formatted like this (as of 9 April 2010; red circle added):
(source: ggpht.com)