2007 marked the year that I switched shells. I used to use the Hamilton C Shell, which was powerful and integrates exceptionally well with Windows, but I found myself constantly having to relearn the script syntax whenever I'd want to do something. So when PowerShell came along, I bought Bruce's book and went to town with it. There are so many things I love about PowerShell that it'll take many blog entries to cover them all.
One of the problems I solved that I've had on my list of "blog topics" for ages was how to set ACLs on files using PowerShell. Below is a *very* basic script that will get you started. This grants a user named "keith" permission to modify a file called "foo.txt" in the current directory. It's the simplest example I can think of that demonstrates the idea. I'll explore this in future posts and eventually translate it into a more universal script that you can use in production, but this should get you thinking!
$dacl = (dir foo.txt).GetAccessControl()
$newRule = New-Object Security.AccessControl.FileSystemAccessRule "keith",
Modify, Allow
$modified = $false
$dacl.ModifyAccessRule("Add", $newRule, [ref]$modified)
(dir foo.txt).SetAccessControl($dacl)
Navigate posts in this series: next
Posted
Oct 23 2007, 08:29 AM
by
keith-brown