本篇将介绍如何用PowerShell创建一个共享并且给Everyone全部访问(Full Access)的权限。
这里应用到以下Windows Class,如果有需要可以查看微软官方的开发文档。
Win32_trustee官方文档:
https://msdn.microsoft.com/en-us/library/aa394501%28v=vs.85%29.aspx
Win32_ACE官方文档:
https://msdn.microsoft.com/en-us/library/aa394063%28v=vs.85%29.aspx
Win32_SecurityDescriptor官方文档:
https://msdn.microsoft.com/en-us/library/aa394402%28v=vs.85%29.aspx
因为每一个Class都需要声明相应的元素,因此不能错过每一个元素的声明,要不然就会找不到相应的Property。
全部脚本:
$trustee.Name = "EVERYONE"
$trustee.Domain = $Null
#Username/Group to give permissions to
$trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
$trustee.Domain = $null
$trustee.Name = "EVERYONE"
#Accessmask values
$fullcontrol = 2032127
$change = 1245631
$read = 1179785
#Create access-list
$ace = ([wmiclass]'Win32_ACE').psbase.CreateInstance()
$ace.AccessMask = $fullcontrol
$ace.AceFlags = 3
$ace.AceType = 0
$ace.Trustee = $trustee
#Securitydescriptor containting access
$sd = ([wmiclass]'Win32_SecurityDescriptor').psbase.CreateInstance()
$sd.ControlFlags = 4
$sd.DACL = $ace
$sd.group = $trustee
$sd.owner = $trustee
$share = Get-WmiObject Win32_Share -List
$share.create("d:testfolder", "testshare$", 0, 100, "Description", "", $sd)