Skip to content

PS7 issue with .GetAccessControl() not in .Net Core #9

@gaelcolas

Description

@gaelcolas

This trick does not work with PS7.
The API has changed between .Net 4.x and .net core.

https://github.com/dsccommunity/FileSystemDsc/blob/master/source/DSCResources/DSC_FileSystemAccessRule/DSC_FileSystemAccessRule.psm1#L611

I think the below should work (ok in PS7):

function Get-ACLAccess
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [System.String]
        $Path
    )
    $EmptyAcl = [System.Security.AccessControl.DirectorySecurity]::new()
    $ACL = (Get-Acl -Path $Path)
    $ACL.Access.Foreach{$EmptyAcl.Access.AddRule($_)}
    return $ACL
}

Here's how I tested:

$FileSystemAccessRuleProperties = @{
    Path = 'C:\src\testACL'
    Identity = 'AzureAD\GaelColas'
    Rights = @('FullControl')
}

$invokeDscResourceParams = @{
    Name = 'FileSystemAccessRule'
    ModuleName = 'FileSystemDsc'
    Property = $FileSystemAccessRuleProperties
}

if (-not (Invoke-DscResource @invokeDscResourceParams -Method Test).InDesiredState ){
    Invoke-DscResource @invokeDscResourceParams -Method Set -Verbose
}

Invoke-DscResource @invokeDscResourceParams -Method Test

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThe issue is a bug.help wantedThe issue is up for grabs for anyone in the community.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions