Powershell security warning

Hi all - long time since I’ve posted here and just had to re-write this since Wordpress had a fail on me and deleted my original post, so forgive any bad grammar :confused:

I’ve been looking for years to find a way to disable Powershell’s annoying security warnings. Recently I’ve started to script some more, and its gotten to the point now that its making me angry every time I try to debug or write anything.

Is there a way to properly disable the Powerhsell security warnings that pop up every time you run a script? I write all my own scripts, so usually dont bother to sign them or anything (no point) and I often write little scriptlets to help me automate tasks.

Most of what I code is done to automate really basic stuff, or things like a full on server deployment. They rely entirely on zero-touch from the user/admin running them, so this security warning always throws a spanner in the works. I kick off a server deployment using my script for e.g. and come back hours later expecting it to be done only to find it stuck on this infuriating warning screen:

Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this script can potentially harm your computer. If you trust this script, use the Unblock-File cmdlet to allow the script to run without this warning message. Do you want to run <path-to-file>?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”):

I’ve searched online long and hard for a solution, and nothing I’ve tried seems to do anything with this warning message.

  • Set-ExecutionPolicy to bypass - does nothing
  • Setting Intranet zone security for SMB shares (my scripts are stored on our network SMB shares) - does nothing
  • Setting GPOs to disable POSH security - does nothing
  • Unblock-File cmd - does nothing!
I've even attempted using some janky workaround using SysInternals Streams to try and sort the security zones out, but I couldnt figure out what they were trying to achieve with that method - just dont understand it enough.

My question is simple - how do I disable these warnings?

And why is this information so well hidden from Microsoft? I’ve tried to structure my google searches in multiple ways but found nothing that’s helped - either I’m looking in the wrong places, or using some wrong search criteria.

Thanks all

Greg

Try unblocking the file.

From Windows Explorer, locate your file. Right-click –> Properties –> Click the Unblock checkbox –> Apply –> OK

Thanks for the response - but this doesnt work either (forgot to mention I’d tried it).

I just tested it again using a new script I’m writing and nothing changed.

I ran Unblock-File cmdlet on the file in question, and the security warning pops up still every time. Tried in explorer and got the same thing.

This also wont work for my automation scripts, especially ones that do server deployments. Is there anyway to remove user input?

Greg, how are you running the script? Are you opening powershell.exe first then running, clicking a shortcut to run it, going into cmd and typing powershell.exe <file>? Is the machine on a AD domain?

Open PowerShell and without doing anything else run this and post the results:

Get-ExecutionPolicy -List

This message is almost always an execution policy issue. By answering those questions, I might be able to help.