PowerShell execution policy not working or…
Monday, 8. December 2008 23:05
Regardless of the execution policy you specified, PowerShell will ask you if you want to continue running a script when running it from an un-trusted source like a website or a file share on some server on your network. If you run into this, just use the “set-executionpolicy” command and add the source to the list of trusted sites in the Internet Explorer. Problem fixed… or is it?
In the notepad below you will find and extremely complicated script which would normally display the words “Hello” and “World” on the same line on console.
I was pretty sure I set the execution policy to “Unrestricted” but still I was unable to run this script. The results are shown below and as you can see, the execution policy is set to unrestricted and I pretty much trust my own C drive.
So, why doesn’t it run? You could of course try to set the execution policy a couple of times to see if it makes any difference. You could even trust all the sites in the whole wide world but chances are you ran into Alternate Data Streams. This nice little feature of NTFS allows more information than the eye or Windows Explorer can see to be stored on your file system.
To check if you are dealing with Alternate Data Streams you can use a tool appropriately called “streams” by Mark Russinovich. Download here. So when I ran this tool against my script I found that some dark matter was attached to my script and it was called “:Zone.Identifier:$DATA”.
To examine to contents of this dark matter I fired up notepad, the integrated development studio for real men, like shown below.
There was some information about zones in there, but actually I couldn’t care less. I just wanted my script to run. Fortunately, the streams tool not only allows you to see the alternate streams, it also allows you to delete them
Hello World
Category:PowerShell | Comments (3) | Author: Dennis Damen