PowerShell Remoting Project Home

Tuesday, January 03, 2006

Play with ACL in MSH (continued)

/\/\o\/\/ kindly replied my blog entry “Play with ACL in MSH”. In his blog entry “Adding a Simple AccesRule to a file ACL in MSH”, he found a shortcut to create an instance of “System.Security.AccessControl.FileSystemAccessRule”. Great job! But things can get even better!

1. You want to change a accessrule but not overwrite it, so AddAccessRule() method is better than SetAccessRule() method. If you want to grant a FullControl privilege to exact same user, they are the same. What if you want to apply a more complex privilege? For example: Read + Write nut not Delete.

2. get-acl cmdlet return different object:
For a file, it will return “System.Security.AccessControl.FileSecurity”;
For a directory, it will return “System.Security.AccessControl.DirectorySecurity”.
Luckily enough, both object have AddAccessRule() and RemoveAccessRule() methods. And Even better, both methods take a “System.Security.AccessControl.FileSystemAccessRule” as parameter. So we can set Access control of a file or directory in one simple script.

# AddRemove-AccessRule.MSH
# Add or remove simple access rule to a file/directory
# using text parameters
# original writen by /\/\o\/\/ 2006
# http://mow001.blogspot.com
# modified by tony 2006
# http://mshforfun.blogspot.com
#Usage AddRemove-Acl FileOrDirectory (Action) user Rights (Access)
# Action: Add / Remove
# Rights: ListDirectory / ReadData / WriteData / CreateFiles /
# CreateDirectories / AppendData / ReadExtendedAttributes /
# WriteExtendedAttributes / Traverse / ExecuteFile /
# DeleteSubdirectoriesAndFiles / ReadAttributes / WriteAttributes/ Write /
# Delete / ReadPermissions / Read / ReadAndExecute / Modify /
# ChangePermissions / TakeOwnership / Synchronize / FullControl
# Access: Allow / Deny

Param (
$Action = "Add",
[System.Security.AccessControl.FileSystemRights] $Rights,
[System.Security.AccessControl.AccessControlType] $Access = "Allow"


$AccessControl = get-acl $FileDir

$AccessRule = new-object System.Security.AccessControl.FileSystemAccessRule($User,$Rights,$Access)

# check if given user is Valid, this will break function if not so.
$Sid = $AccessRule.IdentityReference.Translate([System.Security.Principal.securityidentifier])

resolve-path $FileDir

"Before changes"

if ($Action.ToUpper() -eq "ADD") {$AccessControl.AddAccessRule($AccessRule)}
elseif ($Action.ToUpper() -eq "REMOVE") {$AccessControl.RemoveAccessRule($AccessRule)}

set-acl -aclobject $AccessControl -path $FileDir

"After " + $Action + " access rule: " + "User-"+ $User + " Rights-" + $Rights + " Access-" + $Access
(get-acl $FileDir).AccessToString

[Edit: Monad has now been renamed to Windows PowerShell. This script or discussion may require slight adjustments before it applies directly to newer builds.]


This momentousdecree wow gold came as a great beacon gold in wow light of hope buy wow gold to millions of negroslaves wow gold kaufen who had been seared in the flames of withering injustice.maplestory mesos it came as a joyous daybreak to end the long night ofcaptivity.but one hundred years later,maplestory money we must face the tragic fact thatthe negro is still not free.maple money one hundred years later,sell wow gold the lifeof the negro is still sadly crippled by the manacles ofsegregation and the chains of discrimination. one hundred yearslater,maple story money the negro lives on a lonely island of poverty in themidst of a vast ocean of material prosperity.wow powerleveling one hundred yearslater,maple story power leveling the negro is still languishing in the corners of americansociety and finds himself an exile in his own land. so we havecome here today to dramatize wow powerleveln an appalling condition.in a ms mesos sense we have come to our nation''s capital to cash a check.when the architects of our republic wow powerleveln wrote the magnificent wordsof the constitution and the declaration of independence, theywere signing a promissory note maplestory power leveling to which every american was tofall heir.
Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa

Post a Comment

Links to this post:

Create a Link

<< Home