I don't know if you forgot the - in your question but it's -ExecutionPolicy
. If that script isn't signed then it won't execute that script also, you can use bypass
as the executionpolicy to rule that out.
I doubt you can run scripts and commands one after another in the command line. Add the exit $LASTEXITCODE
to the script and run it with the -File C:\script.ps1
.
If by run hidden you mean no console window, I usually call my scripts like
powershell.exe -noprofile -executionpolicy bypass -file C:\script.ps1
and never see a window.
To get the output of your script into a file, pipe your commands into Tee-Object
"Hello World" | Tee-Object C:\output.file
You can name the file anything you like, implement logic in your script so the file name increments, or - my personal favorite - use YYYYMMddhhmmss in the file name.
Update
Also, taken from Microsoft's Technet Page on Powershell:
Script blocks must be enclosed in braces ({}). You can specify a script block only when running PowerShell.exe in Windows PowerShell. The results of the script are returned to the parent shell as deserialized XML objects, not live objects.
If the value of Command is a string, Command must be the last parameter in the command , because any characters typed after the command are interpreted as the command arguments.