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:
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.