Search code examples
powershellsecuritywmiaccess-rights

wmi SetSecurityDescriptor


Try to grant access right on systemroot by wmi with sddl, but get an error of invalid parameter. This is my function:

function GrantSysRoot
{
    Param (
        [string]$strcomputer
    )  
    $sec =  Get-WmiObject -Class Win32_LogicalFileSecuritySetting -Filter "Path='C:\\Windows'" -ComputerName $strcomputer
    $converter = New-Object System.Management.ManagementClass Win32_SecurityDescriptorHelper
    $sddl = $converter.Win32SDToSDDL($sec.GetSecurityDescriptor().Descriptor)
    $newSDDL = $sddl.SDDL += "(" + $SRSDDL + ")"
    $Win32descriptor = $converter.SDDLToWin32SD($newSDDL)
    $result = $sec.SetSecurityDescriptor($Win32descriptor)

    if ($result.ReturnValue -eq 0) {
        LogWrite "Success SystemRoot setting rights"
    } 
    else {
        LogWrite "An error occured with SystemRoot rights settings"
    }
}

The SetSecurityDescriptor method returned Invalid parameter error. Have any idea?


Solution

  • Resolved, we have to use property "descriptor"

    $result = $sec.SetSecurityDescriptor($Win32descriptor.Descriptor)