Reputation: 67
When I'm trying to run a PowerShell Script .ps1 file via Task Scheduler
like this I get 0*1 Error
powershell.exe
arguments :-File "E:\v tes\hash v.ps1"
but when running the command with the following:
-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass `
-File "E:\v tes\hash v.ps1"
It seems to be Working
Do I need to worry about bypassing the ExecutionPolicy ?
Are there any Security risks when bypassing the Execution Policy in PowerShell by running a command with ExecutionPolicy in Bypass?
Upvotes: 1
Views: 3358
Reputation: 27576
No. The purpose of the security policy is to not unknowingly run a powershell script, like when received as an email attachment. In later versions of the os, the default policy is remotesigned.
Upvotes: 0
Reputation: 13567
PowerShell's default ExecutionPolicy is Restricted, meaning no scripts can be run. This is important for safety, as PowerShell can be used effectively to own a machine.
If you have a specific script you want to run, and the script will not change, you could look at signing that particular script. This is a very safe way of running one script on a schedule, and is the best practice way of doing it.
"Do I need to worry about bypassing the Execution Policy"
It really depends on how worthwhile of a target your organization is. Here's why it is dangerous for you to set a schedule task in bypass mode.
Anyone with access to the machine could replace that script with anything they want and it will still be executed. Do not do this.
Now if the machine is in a hardened location with no physical access and it's for a personal script on your home PC, sure, go for it. If it's mission critical or could touch the web or you're in an important industry, don't take this risky shortcut.
"Well what can I do then?"
If you need to run a script on a schedule, just sign the script and if it is ever tampered or changed, the signing won't match and it will not run. This will get you started: How to sign scripts
Upvotes: 1
Reputation: 241
Calling -ExecutionPolicy Bypass
in your task is only Bypassing the normal execution policy for that task. It will do it each time it runs but you are not changing the overall execution policy of the system by doing this.
The execution policy is there to protect you from accidentally running something you didn't mean to in a script, its not really security system as such. Using Bypass for the tasks you need would be safer than adjusting the whole systems execution policy down to remote signed or all signed or unrestricted for instance, as long as you understand what your script is doing.
Info is below about the execution policy in general
Upvotes: 1