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