This is always my answer to all those "compile your .ps1" solutions that are floating around. Why would you wrap your PowerShell in an exe and some custom host?
Just paste this header on the top of your PowerShell script, and then before you share it, rename it with the .cmd
extension. While you're writing, it's a nice syntax-highlighted PowerShell script, and when you rename it, *poof*
it's double-clickable. Drop it in the PATH and you can execute it from the Run dialog or from PowerShell, batch, whatever.
Because there are still people around who actually use CMD, I've updated it to show how to handle passing parameters.
A couple of notes:
- It runs with
ExecutionPolicy
unrestricted because if you're still using CMD you probably haven't configured your ExecutionPolicy - It uses
-NoProfile
to make sure the environment is the same on everyone's PC... - It only creates
function :: {}
because that allows us to ignore the :: on the first line