Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Unable to set NTFS permissions on share using PowerShell. The user shows up with no rights checked off.

$
0
0

I am having a little problem here with setting NTFS permissions via PowerShell. 

Basically I am able to make a new directory on the share, and assign a user NTFS permissions however it just assigns the select user without any permissions set.

$username = "test.user"
$directory = "\\testlab-sv01\Share\newfolder"

New-Item -Path $directory -ItemType Directory

$colRights = [System.Security.AccessControl.FileSystemRights]"FullControl" 

$InheritanceFlag = [System.Security.AccessControl.InheritanceFlags]::ContainerInherit 
$PropagationFlag = [System.Security.AccessControl.PropagationFlags]::InheritOnly 

$objType =[System.Security.AccessControl.AccessControlType]::Allow 

$objUser = New-Object System.Security.Principal.NTAccount("$username") 

$objACE = New-Object System.Security.AccessControl.FileSystemAccessRule($objUser, $colRights, $InheritanceFlag, $PropagationFlag, $objType) 

$objACL = Get-ACL $directory 
$objACL.AddAccessRule($objACE)

Set-ACL $directory $objACL

A side question, why isn't this native in Powershell? Is it for security reasons? I expected there to be a cmdlet for it. 

Thanks. 


Kyle


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>