Categories Menu
Repair Center
24 hours online support we repair all types of laptops and relating to LCD screen,motherboard, DC adapter, power supplies and so much more! The shop reliable laptop repair in Ottawa area since 1995. Repair your laptop as easy as 1-2-3 !
computer_25
Services for your location
How can I set folder permission with powershell
print
report error
add to favorites
write a review
send to friends
suggest a topic
register

Q: I have been trying to write a script that will allow me to set specific
folder permissions on my profiles folders in my domain. I cannot garauntee
that I am the owner of the folder so the set-acl cmdlt will not work as far
as i understand. I would be open to any option at this point of how to set
permission on many folders with a powershell script.

I have also tried to use cacls, xcacls, and Icacls to no avail. They seem
to work fine if i manually specify the usernames. If I refrence a variable
that holds the username then it craps out on me. I am still open to the
cacls route if someone has had better experience.

At this point I will entertain any solution.

Thanks
Jacob sampson

 

Have tou read this link: http://support.microsoft.com/kb/274443 - this is
right way.

The wron way is to use WMI:

$path = "C:\Test"
$user = "Administrator"
$path = $path.replace("\", "\\")
$SD = ([WMIClass] "Win32_SecurityDescriptor").CreateInstance()
$ace = ([WMIClass] "Win32_ace").CreateInstance()
$Trustee = ([WMIClass] "Win32_Trustee").CreateInstance()
$SID = (new-object security.principal.ntaccount
$user).translate([security.principal.securityidentifier])
[byte[]] $SIDArray = ,0 * $SID.BinaryLength
$SID.GetBinaryForm($SIDArray,0)
$Trustee.Name = $user
$Trustee.SID = $SIDArray
$ace.AccessMask =
[System.Security.AccessControl.FileSystemRights]"FullControl"
$ace.AceFlags = "0x3"
$ace.AceType = 0
$ace.Trustee = $trustee
# get current ACL from DACL
$oldDACL = (gwmi Win32_LogicalFileSecuritySetting -filter
"path='$path'").GetSecurityDescriptor().Descriptor.DACL
# add current DACL to new DACL object
$SD.DACL = $oldDACL
# and add new ACE to DACL
$SD.DACL += @($ace.psobject.baseobject)
# set SE_DACL_PRESENT flag
$SD.ControlFlags = "0x4"
$folder = gwmi Win32_LogicalFileSecuritySetting -filter "path='$path'"
# write new DACL to object ACL
$folder.setsecuritydescriptor($SD)

perhaps xcacls/icacls will be more simple solution.
--
WBR, Vadims Podans
MVP: PowerShell
PowerShell blog - www.sysadmins.lv

 

Article Source: www.vistax64.com
Article Submitted On: 2009-09-18 20:44:47
This article has been viewed 995 time(s).
Other newly Articles from the Operating systems winXP/2000/Vista /Linux /Win 7 - Windows Vista Category:
  1. Vista system—how to add IPX/SPX protocol?
  2. Permanently Activate Windows Vista by Skip Activation with Patched...
  3. Solution for SATA blue-screen in Windows 7
  4. How to Change the Recovery Console Administrator Password on a Domain Controller
  5. How To: Set Processor Affinity To An Application(Or Process) In Windows Vista
  6. Vista system is very slow—6 solutions to simplify debugging
  7. Auto clear virtual memory page in Vista
  8. How can I set folder permission with powershell
  9. Windows Vista Problems: Internet Explorer 8
  10. fix MBR in Vista
  11. Use netsh wlan command to configure wireless network in Vista
  12. Top 10 Windows Vista Performance Tweaks
  13. How to let Windows 7 recognize video file of Real format?
  14. How to Install Windows 7 Beta on an Acer Aspire One Netbook ?
  15. How to delete the hidden partition EISA configured in Windows?
Custom Search
Examples: HP,laptop Rapair,LCD,DC Backlight,Inverter,solder
Article Comment:Replies(0)Views
Name(required):        Email(required):  
Verify: key
Use the above information at your own risk
Loading ... Loading ...