Quick & Dirty way to run PowerShell as a scheduled task

The PowerShell execution policy is there to protect us but not to stop us from doing the ‘not so best practice‘ things.

Best practice would be to sign all your scripts with a code signing certificate, and by using ISE Steroids this makes this process much much easier with the click of a button.

However there are times you just want to run a PowerShell script ‘as is‘ with the guarantee it will run – bearing in mind the default behaviour of a computer is Remote Signed meaning a PowerShell script from any remote source needs to be signed with a trusted certificate.

This is how you can do it on those ad-hoc occasions:

powershell.exe -ExecutionPolicy Unrestricted -File C:\script.ps1

And you can pop it into a scheduled task:

2017-10-18_1306

Below is an example how to map a network drive to Azure Files using PowerShell:

Save this script above as c:\M-Drive.ps1 (as an example).

Below is an example on how to add this PowerShell script as a scheduled task to ensure it is run as part of the user context.

PowerShell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: