{"id":4977,"date":"2012-09-14T00:01:00","date_gmt":"2012-09-14T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2012\/09\/14\/easily-unblock-all-files-in-a-directory-using-powershell\/"},"modified":"2012-09-14T00:01:00","modified_gmt":"2012-09-14T00:01:00","slug":"easily-unblock-all-files-in-a-directory-using-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/easily-unblock-all-files-in-a-directory-using-powershell\/","title":{"rendered":"Easily Unblock All Files in a Directory Using PowerShell"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to unblock all files in a directory.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. Today is the day. As those of you who have been reading the Hey, Scripting Guy! Blog on a regular basis know, today is the speaker&rsquo;s dinner (and scripting slumber party) for <a href=\"http:\/\/powershellsaturday.com\/002\/\" target=\"_blank\">Windows PowerShell Saturday<\/a> in Charlotte, North Carolina. The speaker&rsquo;s dinner and slumber party take place at the house that script built, and the Scripting Wife and I are the hosts. Check the website to see if any tickets remain&mdash;they have been flying off the shelves this week. If at all possible, you do not want to miss Windows PowerShell Saturday in Charlotte because there is an all-star lineup of speakers, and with three tracks and lots of sessions to choose from, it will be a learning extravaganza. Having just returned from Redmond (or the &ldquo;mother ship&rdquo; as some of my more sarcastic friends refer to the Microsoft headquarters), I am definitely pumped up, psyched-out, hyped-up (or whatever enthusiastic adverb you wish to use to describe me). Teresa will have a hard time restraining me as I deliver my two presentations on Windows PowerShell cool stuff!<\/p>\n<h2>The problem with blocked files<\/h2>\n<p>So, when I was getting ready to head out to Redmond for the week, I needed to ensure I had my Hey, Scripting Guy! Blog template copied on my corporate laptop. I do not normally use this laptop to write my blog because it simplifies things if I use a machine connected to my test lab instead of having to demonstrate alternate credentials for every single command.<\/p>\n<p>So I copied my template file to a USB drive from my lab environment computer, and pasted the template to my corporate network-joined laptop. Cool, sneaker net rules! Then I opened the file, and I was greeted with a non-working file. The Microsoft Word document had a big yellow bar across the top informing me that I am in <i>Protected View. <\/i>Well, that may be fine for reading a document, but when you are a Scripting Guy with lots of people with whom to meet, and lots of blogs to write, suffice to say, the Protected View does not work. Sure, I can click <b>Enable Editing<\/b><i>, <\/i>but that is just annoying. This view is shown in the image that follows.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5481.hsg-9-14-12-1.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5481.hsg-9-14-12-1.png\" alt=\"Image of document\" title=\"Image of document\" \/><\/a><\/p>\n<h2>Unblocking all files in a folder<\/h2>\n<p>Luckily, Windows PowerShell&nbsp;3.0 in Windows&nbsp;8 has the <b>Unblock-File<\/b> cmdlet. In the past, I have used the Streams utility to perform this operation&mdash;in fact, I showed the Scripting Wife how to do this in <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/04\/02\/scripting-wife-learns-about-unblocking-files-in-powershell.aspx\" target=\"_blank\">Scripting Wife Learns About Unblocking Files in PowerShell<\/a>. If you do not have Windows&nbsp;8, you can still use the technique from that post to unblock files. It works great (even if the Scripting Wife did accuse me of breaking her computer).<\/p>\n<p>To unblock all the files in a folder, I first use the <b>Get-ChildItem<\/b> cmdlet to return a list of <b>FileInfo<\/b> objects from the directory, and then I pipe them to the <b>Unblock-File<\/b> cmdlet. Because I am changing system state (modifying a potentially great number of files), I want to first ensure that the command does what I want it to do, so I use the <b>WhatIf<\/b><i> <\/i>parameter. This is shown here. (<b>gci<\/b> is an alias for the <b>Get-ChildItem<\/b> cmdlet.)<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1207.hsg-9-14-12-2.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1207.hsg-9-14-12-2.png\" alt=\"Image of command output\" title=\"Image of command output\" \/><\/a><\/p>\n<p>That looks like exactly what I want to accomplish, so I remove the <b>WhatIf<\/b><i> <\/i>parameter and run the following command.<\/p>\n<p style=\"padding-left: 30px\">gci c:\\fso | Unblock-File<\/p>\n<p>Like I said, nothing returns. So I need to perform a test to see if the command worked. I open my HSG-Template.docx file, and as you can see here, the yellow blocking bar is now removed.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8424.hsg-9-14-12-3.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8424.hsg-9-14-12-3.png\" alt=\"Image of document\" title=\"Image of document\" \/><\/a><\/p>\n<p>That is about all there is to unblocking files with Windows PowerShell&nbsp;3.0. If you want to control which files to unblock, use the parameters of the <b>Get-ChildItem<\/b> cmdlet to modify the way you return files.<\/p>\n<p>Join me tomorrow when I will talk about more cool Windows PowerShell stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to unblock all files in a directory. Microsoft Scripting Guy, Ed Wilson, is here. Today is the day. As those of you who have been reading the Hey, Scripting Guy! Blog on a regular basis know, today is the speaker&rsquo;s dinner (and scripting [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[38,84,49,364,3,12,367,45],"class_list":["post-4977","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-files","tag-microsoft-word","tag-office","tag-powershell-3-0","tag-scripting-guy","tag-storage","tag-windows-8","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to use Windows PowerShell to unblock all files in a directory. Microsoft Scripting Guy, Ed Wilson, is here. Today is the day. As those of you who have been reading the Hey, Scripting Guy! Blog on a regular basis know, today is the speaker&rsquo;s dinner (and scripting [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=4977"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/4977\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=4977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=4977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=4977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}