So, this works and yes you can use it with a script. If you think it's failing with a script, my suggestion is to try using "dir" as your first command, you may be working in a directory that you're not aware.
Some things to know:
1. You want to use SSL, and yes you can make a Self-Signed cert and use it, just disable verification here. There are tutorials online for that if you are not aware.
2. You need to manually create a listener using the thumbprint of that cert, on port 5986, or whatever port you please.
3. You should probably use a service account and limit access, your call.
4. Make sure your powershell script runs and not opens, or you get a desired output. I recommend just being sure it can do something like output to a dummy file to know it's working. My script writes "Hello World" to a text file.
If you get the cert and the winrm listener created, then this is an example of how to use a script.
dir
Start-Process -FilePath "C:\Users\jgranger\Desktop\test.ps1"