5 Responses to Windows Share Permissions and Using Powershell to Manipulate Them

  1. Pingback: Exporting Share Info and Permissions with PowerShell and CSV files | Windows Stuff That Your Dreams Dreamed Of

  2. Pingback: Importing Share Info and Permissions with PowerShell and a CSV file | Windows Stuff That Your Dreams Dreamed Of

  3. Pingback: Importing Share Info and Permissions with Powershell and a CSV file (cont’d) | Windows Stuff That Your Dreams Dreamed Of

  4. jeff converse says:

    Very usefull information. My question (hoping you can assist) is how do I set the share permissions for Authenticated Users Change and remove Everyone? Every time I run this, I create the share but Everyone is granted FULL. Can you help?
    $Computer = “localhost”
    $Class = “Win32_Share”
    $Method = “Create”
    $name = “TEMP”
    $path = “C:\temp”
    $description = “This is shared for me to test”
    $sd = ([WMIClass] “\\$Computer\root\cimv2:Win32_SecurityDescriptor”).CreateInstance()
    $ACE = ([WMIClass] “\\$Computer\root\cimv2:Win32_ACE”).CreateInstance()
    $Trustee = ([WMIClass] “\\$Computer\root\cimv2:Win32_Trustee”).CreateInstance()
    $Trustee.Name = “Authenticated Users”
    $Trustee.Domain = “NT AUTHORITY”
    $Trustee.SID = @(1, 1, 0, 0, 0, 0, 0, 5, 11, 0, 0, 0)
    $ace.AccessMask = 1245631
    $ace.AceFlags = 4
    $ace.AceType = 0
    $ACE.Trustee = $Trustee
    $sd.DACL += $ACE.psObject.baseobject
    $mc = [WmiClass]”\\$Computer\ROOT\CIMV2:$Class”
    $InParams = $mc.psbase.GetMethodParameters($Method)
    $InParams.Access = $Null
    $InParams.Description = $description
    $InParams.MaximumAllowed = $Null
    $InParams.Name = $name
    $InParams.Password = $Null
    $InParams.Path = $path
    $InParams.Type = [uint32]0
    $R = $mc.PSBase.InvokeMethod($Method, $InParams, $Null)
    switch ($($R.ReturnValue))
    {
    0 {Write-Host “Share:$name Path:$path Result:Success”; break}
    2 {Write-Host “Share:$name Path:$path Result:Access Denied” -foregroundcolor red -backgroundcolor yellow;break}
    8 {Write-Host “Share:$name Path:$path Result:Unknown Failure” -foregroundcolor red -backgroundcolor yellow;break}
    9 {Write-Host “Share:$name Path:$path Result:Invalid Name” -foregroundcolor red -backgroundcolor yellow;break}
    10 {Write-Host “Share:$name Path:$path Result:Invalid Level” -foregroundcolor red -backgroundcolor yellow;break}
    21 {Write-Host “Share:$name Path:$path Result:Invalid Parameter” -foregroundcolor red -backgroundcolor yellow;break}
    22 {Write-Host “Share:$name Path:$path Result:Duplicate Share” -foregroundcolor red -backgroundcolor yellow;break}
    23 {Write-Host “Share:$name Path:$path Result:Reedirected Path” -foregroundcolor red -backgroundcolor yellow;break}
    24 {Write-Host “Share:$name Path:$path Result:Unknown Device or Directory” -foregroundcolor red -backgroundcolor yellow;break}
    25 {Write-Host “Share:$name Path:$path Result:Network Name Not Found” -foregroundcolor red -backgroundcolor yellow;break}
    default {Write-Host “Share:$name Path:$path Result:*** Unknown Error ***” -foregroundcolor red -backgroundcolor yellow;break}
    }

    • Jeff,
      Thanks for your comment. It seems that you have $null for your InParams.Access value. You should have your built security descriptor here ($sd.psobject.baseobject). This should set access according to your access mask value, I assume it was defaulting to full control.

Leave a comment