r/Batch • • Aug 04 '26

Show 'n Tell ps1.cmd: Running PowerShell scripts by double-clicking via a .cmd wrapper

/r/PowerShell/comments/1vezy5s/ps1cmd_running_powershell_scripts_by/
1 Upvotes

1 comment sorted by

4

u/T3RRYT3RR0R Aug 04 '26

Batch / powershell hybrids have been a solved problem for rather some years.  The standard convention is:

    <# : batch portion
    :# The above line marks the beginning of a powershell comment block; and the Batch component of the Script. Do not modify.
        
    @echo off
    
    If not exist "%~dpn0.ps1" Copy "%~f0" "%~dpn0.ps1" 1> nul 2> nul
    
    powershell.exe -noprofile -ExecutionPolicy Bypass -file "%~dpn0.ps1"
    
    
    :# The below line Marks the end of a Powershell comment Block; And the End of the Batch Script. Do not Modify.
    : end batch / begin powershell #>

Such hybrids can be used as wrappers or as a multi-process work flow replete with ipc to augment batch capabilities.