Scripting Wife Learns About Unblocking Files in PowerShell

Scripting Wife Learns About Unblocking Files in PowerShell

  • Comments 6
  • Likes

Summary: The Scripting Wife learns how to unblock files that are downloaded from the Internet by using Windows PowerShell and a Sysinternals tool.

Microsoft Scripting Guy, Ed Wilson, here. It is two days until the 2011 Scripting Games kick off. Things are quiet right now, and I am enjoying a chance to catch my breath and to relax. I am thinking about spending the day reading Sherlock Holmes. I have my Windows 7 Smartphone beside me, so I can monitor Twitter and email without even leaving my reading chair.

I had called upon my friend, Mr. Sherlock Holmes, one day in the autumn of last year and found him in deep conversation with a very stout, florid-faced elderly gentleman with fiery red hair,” I read to myself. Suddenly I heard a stomping sound coming across the living room floor. Up the steps into the vestibule, the sound moved, and the vibration that the sound emitted caused my reading lamp to tremble. The light reflecting on the ceiling cast an eerie shadow that began to dance in a frightening manner. It was then that I sensed the presence of another being. I looked up from my book, and standing in the doorway, seething with anger was the Scripting Wife. I waited to see if I was in trouble or not.

“This is stupid,” she began.

I thought about asking what was stupid, but I decided that discretion was the better part of valor, and therefore kept my mouth shut.

“I download the PowerShell Community Extensions from CodePlex on your recommendation, and it does not work,” she continued. “In fact nothing works! You have messed up my computer.”

“Me?” I asked innocently.

“Yeah you, Mr. Innocent. If it were not for you, I would not have installed that stuff, and it would not have hosed my computer,” she nearly yelled. “It’s all your fault.”

“Well let’s see if I, the Microsoft Scripting Guy, can solve the case of the corrupt PSCX install,” I said in my best Basil Rathbone imitation. “Take me to your computer.”

“Now, show me the problem,” I said soothingly.

“When I use the Import-Module cmdlet to import the PSCX module, it gives me a bunch of errors. I tried telling it to run, but it keeps coming back with more errors,” she complained. “Let me show you.”

The Scripting Wife opened the Windows PowerShell console, and typed the following command.

Import-Module pscx

The command and its associated output are shown here.

Image of command output

“Well, I have good news for you. Your computer is not broken. You have run across a feature of Windows PowerShell 2.0. Although you have your script execution policy set to unrestricted, Windows PowerShell uses Internet Explorer’s zone settings. The pscx-2.0.0.1.zip file that you downloaded from CodePlex is marked as coming from the Internet zone. What you should have done was to unblock the file before expanding it. Because every file that was in that zip file is also blocked. This is why you keep getting all the warning messages,” I said.

“OK. So it is not broken, but it acts like it. What I should have or could have done does not fix this problem,” she whined.

“True. But first, let me show you the easy way to unblock a file, in case you wish to download other scripts or modules,” I said. “Right-click the pscx-2.0.0.1.zip file and choose Properties. In the Security section, click the Unblock button, Apply, and OK,” I instructed.

The Scripting Wife navigated to the location where she had downloaded the PSCX module, and unblocked the file. The Properties dialog box for the file is shown here.

Image of dialog box

“After you have unblocked the zip file, expand the contents of the file,” I said.

“OK. So how does that help me?” she said.

“For one thing, all the files that are unzipped are no longer blocked. Look at the Properties of the Pscx.FeedStore.Type.ps1xml file. That was the first file that was blocked,” I said.

The Scripting Wife navigated to the TypeData folder, right-clicked the Pscx.FeedStore.Type.ps1xml file and viewed the Properties. The Properties of the file are shown here.

Image of dialog box

“That is all fine and dandy; however, it does not really help me,” she added.

“You are right. One approach would be to right-click all 81 files in the PSCX module directory and unblock them,” I began.

“Surely you are kidding,” she interrupted.

“My name is Ed, but that is not important right now. As I was saying before you interrupted, that would be one approach. Another approach would be to delete the PSCX module folder and copy your unblocked files into it. But I have a better idea,” I said.

“Don’t keep me in suspense,” she feigned.

“OK. I need you to go to the Sysinternals site on TechNet. When you get there, download the Streams tool. When you download it, make sure you unblock it before you unzip it,” I instructed.

“Yeah. I am getting good at that,” she said.

“The hardest part about using the Streams tool is providing the path to the modules directory. You can copy the path to the PSCX module directory directly from Windows Explorer. First take a look at the Streams tool’s information about all the files in the PSCX module directly. To do that, use the command streams –s and the path that you copied from Windows Explorer,” I said.

Because the Scripting Wife copied the Streams utility into her user directory, and because that is her current working directory, she needs to use the .\\ syntax to tell Windows PowerShell to look for the Streams utility in the current path. She uses the –s parameter to tell the Streams utility to display all of alternate data streams and to recurse for the starting directory. The command and the Windows PowerShell prompt are shown here.

PS C:\Users\teresa> .\\streams -s C:\Users\teresa\Documents\WindowsPowerShell\modules\Pscx

The command and its associated output are shown in the following image.

Image of command output

“Wow, that is a lot of stuff,” she said.

“Notice that each one of the streams says it is zone identifier data. That is what we want to remove,” I said. “Now use the dash d parameter to remove that,” I said.

The Scripting Wife used the Up arrow, and added the –d parameter to the command. Her revised command is shown here.

PS C:\Users\teresa> .\\streams -s -d C:\Users\teresa\Documents\WindowsPowerShell\modules\Pscx

The command and its associated output are shown in the following image.

Image of command output

“Now close your Windows PowerShell console, and open it back up again. Now try to import your PSCX module,” I said.

“Cool, it works. That is great. Well, my little Script Monkey, I will let you get back to your reading. I have things to do,” she said.

“I see. What things are those?” I asked.

“Can’t say. But it is Saturday, and you are doing what you want to do, and I plan to do what I want to do.”

“Fair enough,” I said. “Have a great day.”

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • SERIOUSLY interesting posts. Exposes things I didn't know about the downloaded script security as WELL as the NTFS stream functionality. Wohoo!

    Well done on a great post, even if it exposes that you two script together :p

  • @Nicolas Blank I am glad you learned alot from the article. Thank you! It makes my day when I see good comments. The family that scripts together stays together :-)

  • This is very cool.  BUT....

    What I would really love to do is to only remove the zone stream -- the one that causes the block.  I think that streams -d deletes all streams.

    Now granted, I can't think of one other thing that streams get used for today, so you could argue that I'm being pedantic.  But what if MS, or some other vendor does come up with something else to do with streams?  If that happened, I wouldn't want to delete those streams.  Is there an "unblock" API in Windows that we could expose to Powershell?  WMI command? Other options?

  • I have just discovered that Powershell 3.0 has the Unblock-File cmdlet, which makes things easier !

    technet.microsoft.com/.../hh849924.aspx