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

Set file sharing permission level powershell

$
0
0

Hi.

Please advice how to share the folder with permission level read/write to domain\user. NOT NTFS permissions!!!

I used function below, but it put ntfs permissions. It is possible to set share permissions using PS?

function: 

function shareFolder 
{
	Param ($folder, $uname)
	$name = $folder.Name
	$path = $folder.Fullname
	$sd = ([WMIClass] "Win32_SecurityDescriptor").CreateInstance()
	$ace = ([WMIClass] "Win32_ACE").CreateInstance()
    $Trustee = ([WMIClass] "Win32_Trustee").CreateInstance()
    $Trustee.Name = $uname
    $Trustee.Domain = $null
    $ace.AccessMask = 2032127
    $ace.AceFlags = 3 
    $ace.AceType = 0 
    $ACE.Trustee = $Trustee 
    $sd.DACL += $ace.psObject.baseobject 

	$mc = [WmiClass]"Win32_Share"
    $InParams = $mc.psbase.GetMethodParameters("create")
    $InParams.Access = $sd
    $InParams.Description = "Share"
    $InParams.MaximumAllowed = $Null
    $InParams.Name = "test"
    $InParams.Password = $Null
    $InParams.Path = $folder 
    $InParams.Type = [uint32]0
	$mc.PSBase.InvokeMethod("Create", $InParams, $Null)
}

shareFolder "C:\testshare" "d.local\testuser"

 I repeat it put ntfs permissions, not share.

Viewing all articles
Browse latest Browse all 15028

Trending Articles



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