powershell共享文件夹的权限级别

问题描述 投票:0回答:1

设置文件夹共享权限时遇到一些问题。无法了解在哪种模式下设置用户域\用户的权限

  1. NET SHARE testfolder=C:\test /GRANT:Everyone,FULL设置NTFS权限但不共享文件夹权限
  2. 使用[wmiClass]“Win32-Share”.create()也做同样的事情(写NTFS权限)

如何设置用户与文件夹共享?

powershell-v2.0
1个回答
0
投票

我在下一个函数中使用win32_Share.create():

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 = 524288
$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)

}

共享文件夹“C:\ test”“admin”

在这种情况下,据我所知,ntfs权限正在建立。如何在文件夹上设置“共享权限”(读/写)?

© www.soinside.com 2019 - 2024. All rights reserved.