{"id":73,"date":"2007-02-13T16:40:52","date_gmt":"2007-02-14T00:40:52","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/02\/13\/set-read-only-in-powershell\/"},"modified":"2007-02-13T16:40:52","modified_gmt":"2007-02-14T00:40:52","slug":"set-read-only-in-powershell","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/02\/13\/set-read-only-in-powershell\/","title":{"rendered":"Set Read-Only in PowerShell"},"content":{"rendered":"<p>Here&#8217;s a fast PowerShell tip.&nbsp; Need to mark a file as Read-Only? Use Get-ChildItem to get the file and then invoke the Set_IsReadOnly method.&nbsp; This method needs a Boolean value (True or False) to indicate whether a file is ReadOnly.&nbsp; <\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">(Get-ChildItem e:\\files\\protected.txt).Set_IsReadOnly($True)<\/font><\/p>\n<p>That&#8217;s all there is to it.&nbsp; If you want to check if the file is readonly:<\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">(Get-ChildItem e:\\files\\protected.txt).IsReadOnly<\/font><\/p>\n<p>Will display True or False.<\/p>\n<p>You could also use the set_Attributes method, but be sure to include all the current attributes if you are trying to add ReadOnly. Otherwise set_Attributes will erase the old attributes and use whatever you assign.<\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:8d47826c-b746-44d2-9982-8232cd2ef36c\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\">Technorati tags: <a href=\"http:\/\/technorati.com\/tags\/Powershell\" rel=\"tag\">Powershell<\/a>, <a href=\"http:\/\/technorati.com\/tags\/scripting\" rel=\"tag\">scripting<\/a>, <a href=\"http:\/\/technorati.com\/tags\/FileInfo\" rel=\"tag\">FileInfo<\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a fast PowerShell tip.&nbsp; Need to mark a file as Read-Only? Use Get-ChildItem to get the file and then invoke the Set_IsReadOnly method.&nbsp; This method needs a Boolean value (True or False) to indicate whether a file is ReadOnly.&nbsp; (Get-ChildItem e:\\files\\protected.txt).Set_IsReadOnly($True) That&#8217;s all there is to it.&nbsp; If you want to check if the [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-73","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/73","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}