07-21-2023, 05:47 PM
A solution in the same spirit as UNIX shar (shell archive).
You can put your powershell script in a file with the `.cmd` extension (instead of `.ps1`), and put this at the start:
@echo off
Rem Make powershell read this file, skip a number of lines, and execute it.
Rem This works around .ps1 bad file association as non executables.
PowerShell -Command "Get-Content '%~dpnx0' | Select-Object -Skip 5 | Out-String | Invoke-Expression"
goto :eof
# Start of PowerShell script here
You can put your powershell script in a file with the `.cmd` extension (instead of `.ps1`), and put this at the start:
@echo off
Rem Make powershell read this file, skip a number of lines, and execute it.
Rem This works around .ps1 bad file association as non executables.
PowerShell -Command "Get-Content '%~dpnx0' | Select-Object -Skip 5 | Out-String | Invoke-Expression"
goto :eof
# Start of PowerShell script here