Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gaelcolas opened this issue May 26, 2020 · 0 comments
Open

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

gaelcolas opened this issue May 26, 2020 · 0 comments
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.

Comments

@gaelcolas
Copy link
Member

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
@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Oct 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community.
Projects
None yet
Development

No branches or pull requests

2 participants