How do I write a cmdlet script?

I was a bit shocked at how "difficult" it was to find how to create a cmdlet script.  After all, it was pretty basic to write a cmd (or bat) file and just run it.

Anyway, here's the trick.

rename the file "myscript.ps1" (yes, that's right, .ps1 suffix, not .ps, nor .ps2, and 3 is two too far, 4 would be way out.  .ps1 it shall be).

I'm sure there's a story for this suffix, it would be nice to hear it.

Next, you need to sign your script so PS will allow it to run.  This is covered in numerous places, including the docs that came PS.


set-executionpolicy remotesigned

Will usually give you what you need - unchecked local execution but remote scripts (such as a remote-admin) must be signed.

get-help set-executionpolicy
get-help about_signing