Solved

Read only script powershell

Posted on 2012-04-06
9
704 Views
Last Modified: 2012-04-06
Hi I am looking for a script to mark all ISO files under a directory and subdirectorys as read only. If anyone can help would be much appreciated. thanks in advance
0
Comment
Question by:Dead_Eyes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 16

Expert Comment

by:Dale Harris
ID: 37817545
The easiest way I found is to copy the ACLs from a file that has the same permissions set.  Example:

$ACL = get-acl "c:\examplefile.txt"

Now that it's stored, let's get all the ISO files in a given directory and recursively search

Set-Location "C:\Scripts"
$Files = get-childitem -recurse -filter "*.iso" | %{set-acl $ACL}

I haven't tested this, but this is what it's going to end up looking similar to.  Good luck!  And if you haven't read up on the articles here on EE, I recommend them :)
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/A_4327-PowerShell-Where-do-I-start.html

-DH
0
 
LVL 16

Expert Comment

by:Dale Harris
ID: 37817556
Oh I guess I made a slight error.  After testing, it doesn't like setting the ACL, so let's try this:

$ACL = get-acl "c:\examplefile.txt"
Set-Location "C:\Scripts"
$files = get-childitem -recurse -filter "*.iso"
foreach ($file in $files){
Set-ACL $file $ACL
}

Try that out and see if it doesn't do the job for you.

DH
0
 

Author Comment

by:Dead_Eyes
ID: 37817691
Is the read only attribute part of the acl? (trying it now)
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:Dead_Eyes
ID: 37817730
Gave the script a try and it seems to fail on every fail with the same error

See below:

At C:\test2.ps1:5 char:8
+ Set-ACL <<<<  $file $ACL
    + CategoryInfo          : ObjectNotFound: (X:\Software_Arc...x64_Pro_OEM.iso:String)  
   [Set-Acl], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetAclCommand
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 37817771
No, R/O is a file attribute, not a part of ACLs. We can handle it as a property of the file:
   set-itemProperty c:\temp\File.txt -name IsReadOnly -value $false
or
   (get-itemProperty c:\temp\File.txt).IsReadOnly = $false
0
 

Author Comment

by:Dead_Eyes
ID: 37817874
your definatly on the right track but having alot of trouble trying to translate it into a script
0
 
LVL 16

Accepted Solution

by:
Dale Harris earned 200 total points
ID: 37817899
Oh good call Qlemo, wasn't thinking about that.  Here would be the script change:

Set-Location "C:\Scripts"
get-childitem -recurse -filter "*.iso" | %{$_.isreadonly = $True}

-DH
0
 
LVL 7

Expert Comment

by:BelushiLomax
ID: 37817957
Use icacls with the built in switches. Should do what you need. Included in 08 and 7.
0
 

Author Closing Comment

by:Dead_Eyes
ID: 37817989
Thanks that worked great#
0

Featured Post

What, When and Where - Security Threats from Q1

Join Corey Nachreiner, CTO, and Marc Laliberte, Information Security Threat Analyst, on July 26th as they explore their key findings from the first quarter of 2017.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question