Pergunta

Este é o código que tenho no momento:

$OutFile = "C:\Permissions.csv"
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited"
Del $OutFile
Add-Content -Value $Header -Path $OutFile 

$RootPath = "C:\Test Folder"
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} 

foreach ($Folder in $Folders){
$ACLs = get-acl $Folder.fullname | 
ForEach-Object { $_.Access  } | 
Where {$_.IdentityReference -notlike "*BUILTIN*" -and $_.IdentityReference -notlike "*NT AUTHORITY*"}
Foreach ($ACL in $ACLs){
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference  + "," + $ACL.AccessControlType + "," + $ACL.IsInherited
Add-Content -Value $OutInfo -Path $OutFile
}}

Eu configurei algumas pastas de teste neste caminho de arquivo, uma das quais está além do limite de 260 caracteres do Powershell para aprofundar.

Quando executo esse código, o PS retorna um erro dizendo que o caminho é muito longo e exibe uma versão condensada do caminho do arquivo que apresenta o problema.Existe uma maneira de obter esse caminho, para que eu possa executar o código novamente com o caminho longo no objeto $ RootPath - para que ele possa se aprofundar?

Foi útil?

Solução

Para obter o nome do caminho abreviado, você pode usar Get-ShortPath de Extensões da comunidade PowerShell (PSCX)

Aqui está uma da minha versão antiga (imagino menos poderosa)

# Get the 8.3 short path of a file comming from the pipe (fileInfo or directoryInfo) or from a parameter (string)
Function Get-MyShortPath
{
  [CmdletBinding()]
  PARAM ([Parameter(mandatory=$true,ValueFromPipeline=$true)]
         $file)

  BEGIN
  {
    $fso = New-Object -ComObject Scripting.FileSystemObject
  }

  PROCESS
  {
    if ($file -is [String])
    {
      $file = Get-Item $file
    }

    If ($file.psiscontainer)
    {
      $fso.getfolder($file.fullname).shortPath
    }
    Else 
    {
      $fso.getfile($file.fullname).shortPath
    }
  }
}

uso:

  gci 'C:\Program Files (x86)' | Get-MyShortPath
  Get-MyShortPath 'C:\Program Files'
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top