Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Get-RemoteFolderAcl {
- <#
- .SYNOPSIS
- Returns to ACL of the specified folder from the specified computer
- .DESCRIPTION
- Returns to ACL of the specified folder from the specified computer
- .PARAMETER ComputerName
- The name of the computer
- .PARAMETER Path
- The folder path
- .PARAMETER Credential
- Credentials of the remote computer
- .EXAMPLE
- $cred = Get-Credential
- $folder = @(
- 'C:\temp\folder1'
- 'C:\temp\folder2'
- )
- $acls = Get-RemoteFolderAcl -computerName Computer1 -path $folder -Credential $cred
- $acls | Select PSComputerName, Path, Identity, AccessType, AccessRights | ft
- .NOTES
- #>
- [CmdletBinding()]
- param (
- [Parameter(Mandatory,ValueFromPipeline, ValueFromPipelineByPropertyName)]
- [Alias('PSComputerName')]
- [String[]]$computerName,
- [Parameter(Mandatory,ValueFromPipelineByPropertyName)]
- [alias('Fullname','Folder')]
- [String[]]$path,
- [PSCredential]$Credential
- )
- begin {
- $getAcl = {
- param (
- [String[]]$path
- )
- # permissions hash map
- $permissions = @{
- '268435456' = 'FullControl'
- '-536805376' = 'Modify, Synchronize'
- '-1610612736' = 'ReadAndExecute, Synchronize'
- }
- foreach ($filePath in $path) {
- if (Test-Path $filePath) {
- try {
- Get-Acl $filePath | ForEach-Object {
- foreach ($access in $_.Access) {
- if ($access.FileSystemRights -match '\d') {
- $fsr = $access.FileSystemRights.ToString()
- $fileSystemRights = $($permissions[$fsr])
- }
- else {
- $fileSystemRights = $access.FileSystemRights
- }
- [PSCustomObject]@{
- Path = (($_.Path) -split ("::"))[-1]
- FileSystemRights = $fileSystemRights
- AccessControlType = $access.AccessControlType
- IdentityReference = $access.IdentityReference
- IsInherited = $access.IsInherited
- InheritanceFlags = $access.InheritanceFlags
- PropagationFlags = $access.PropagationFlags
- }
- }
- }
- }
- catch {
- $_.Exception.Message
- }
- }
- else {
- Write-Warning "Computer: [$env:ComputerName] - Folder: [$filePath] doesn't exist"
- }
- }
- }
- }
- process {
- $params = @{
- ComputerName = $computer
- # VMName = $computerName
- ScriptBlock = $getAcl
- ArgumentList = (,$path)
- }
- if ($Credential) {
- $params.Add('Credential', $credential)
- }
- Invoke-Command @params
- # Invoke-Command -VMName $computer -ScriptBlock $getAcl -ArgumentList (,$path)
- # Invoke-Command -ComputerName $computer -ScriptBlock $getAcl -ArgumentList (,$path)
- }
- end {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment