Powershell - Invoke-WmiMethod to create a Sharefolder remotely with full controle permission

前提是你 提交于 2019-11-28 06:44:07

问题


I've been using this script to create my users folders but I just find that the remote share folder is created with ReadOnly share.

My question is how can I create the share folder with $domainname\domain users with full control?

Invoke-WmiMethod -Class win32_share -name Create -ArgumentList `
 @($null,"",100,"hideshare$","",e:\users\hideshare,0) -computername "DestinationSRV"

I've found many threads with answers but not with the method I use.

Any ideas?


回答1:


Try:

#Username/Group to give permissions to
$trustee = ([wmiclass]'Win32_trustee').psbase.CreateInstance()
$trustee.Domain = "domainname"
$trustee.Name = "username or groupname"

#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 -ComputerName "DestinationSRV"
$share.create("e:\users\hideshare", "hideshare$", 0, 100, "Description", "", $sd)

The security for this share will only allow the specified username. You need to modify this(add multiple ace's) to add different groups, add everyone etc..

Source for access-part



来源:https://stackoverflow.com/questions/14345972/powershell-invoke-wmimethod-to-create-a-sharefolder-remotely-with-full-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!