This is a classical batch script that becomes a powershell script.
I was thinking about building a PowerShell script that will decompress and install embeded powershell scripts without using additional files. So I can just copy one file to a computer and install the script with a double click. A MSI package could be an option but that might be a faff for a simple 2 file script, and a pure (sort of) powershell option would be nice. I came up with this proof of concept as a bootstrapping option to get into powershell without extra files or having to open powershell and type commands.
echo "`""<# rem dual dos/ps script @echo off rem the fist line should split cmd and powershell rem in powershell this section looks like a comment rem in dos the script exits before it hits any powershell echo This is dos copy %~dpnx0 %~dpn0.ps1 powershell -executionpolicy remotesigned -file %~dpn0.ps1 exit #> write-host "This is powershell"
Has anyone come up with any other good ways to do this? My short half-hearted Google only came up with multi-file solutions or changing the execution policy (which falls under having to type powershell commands.)
I hope that reddit does not kill the special characters too much.
submitted by /u/purplemonkeymad
[link] [comments]
The post Single File Dos/PowerShell script. appeared first on How to Code .NET.