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

前端 未结 1 1843
猫巷女王i
猫巷女王i 2020-12-20 09:10

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

相关标签:
1条回答
  • 2020-12-20 09:34

    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

    0 讨论(0)
提交回复
热议问题