Home > Back-end >  Issue while executing get-acl for remote servers
Issue while executing get-acl for remote servers

Time:01-05

I am having the below code to get the data from remote servers. thanks to @Santiago Squarzon

$serverlist = Get-Content -Path "C:\ServerList.txt"

# Collect results here
$result = Invoke-Command -ComputerName $serverlist -ScriptBlock {
    $paths_list = $env:Path -Split [System.IO.Path]::PathSeparator
    foreach($sys_Path in $paths_list)
    {
        $Permissions = (Get-Acl -Path $sys_Path).Access
        foreach($acl in $Permissions)
        {
            if(-not $acl.IdentityReference)
            {
                continue
            }   

            [pscustomobject]@{
                ComputerName     = $env:ComputerName
                SystemFolderPath = $sys_Path
                IdenityReference = $acl.IdentityReference.Value
                FileSystemRights = $acl.FileSystemRights
            }
        }
    }
} -HideComputerName

$result | Export-Csv -Path "C:\status_report.csv" -NoTypeInformation

But I am getting below error while executing it

Cannot validate argument on parameter 'Path'. The argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
      CategoryInfo          : InvalidData: (:) [Get-Acl], ParameterBindingValidationException
      FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetAclCommand
      PSComputerName 

Please let me know on this.

CodePudding user response:

Might adding the following check before $Permissions = (Get-Acl -Path $sys_Path).Access would resolve the issue:

if (($sys_Path -eq $null) -or ($sys_Path -eq '') ) {
    continue
}
  •  Tags:  
  • Related