1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#Add-type -Path C:\Dev\AlphaFS-1.5-BinAndDocs\Debug\AlphaFS.dll
Function New-AlphaleonisAccessRules{
param(
[Parameter(Mandatory=$True,position=0)]
$FileSystemRights,
[Parameter(Mandatory=$True,position=1)]
$IsInherited,
[Parameter(Mandatory=$True,position=2)]
$IdentityReference,
[Parameter(Mandatory=$True,position=3)]
$User
)
[pscustomobject]@{
PSTypeName='AlphaleonisAccessRules';
FileSystemRights=$FileSystemRights;
IsInherited=$IsInherited;
IdentityReference=$IdentityReference;
User=$User
}
}# New-AlphaleonisAccessRules
Function New-AlphaleonisACL{
param(
[Parameter(Mandatory=$True,position=0)]
$Path,
[Parameter(position=1)]
$AccessRules=$null
)
[pscustomobject]@{
PSTypeName='AlphaleonisACL';
Path=$Path;
AccessRules=$AccessRules
}
}# New-AlphaleonisACL
function Get-AlphaleonisACL {
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName="Path")]
[string]$Path
)
process {
#Todo File & Directory
#$LongDirectory = [Alphaleonis.Win32.Filesystem.Path]::GetLongPath($Path)
$dir = new-object Alphaleonis.Win32.Filesystem.DirectoryInfo($Path)
$dirACL = $dir.GetAccessControl("Access")
$CurrentDirectory=New-AlphaleonisACL $Path
$CurrentDirectory.AccessRules=@(
foreach($accessRule in $dirACL.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]))
{
# Convert SID to User/group domain
$objSID = New-Object System.Security.Principal.SecurityIdentifier($accessRule.IdentityReference)
$objUser = $objSID.Translate([System.Security.Principal.NTAccount])
New-AlphaleonisAccessRules $accessRule.FileSystemRights $accessRule.IsInherited $accessRule.IdentityReference $objUser
}
)# AccessRules
Write-Output $CurrentDirectory
}#process
} #Get-AlphaleonisACL
Function RecursePath([string]$SourcePath){
[Alphaleonis.Win32.Filesystem.Directory]::GetDirectories($SourcePath) |
Foreach {
$LongDirectory = [Alphaleonis.Win32.Filesystem.Path]::GetLongPath($_)
Get-AlphaleonisACL -path $LongDirectory
RecursePath $LongDirectory
}#foreach Directory
}
$Folders = @(
Get-AlphaleonisACL -Path ([Alphaleonis.Win32.Filesystem.Path]::GetLongPath('C:\temp\001'));
RecursePath -SourcePath 'C:\temp\001'
)#$Folders |
Partager