PowerShell Export Charace Limit Page
-
21-12-2019 - |
Вопрос
Это код, который у меня есть на данный момент:
$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
}}
.
У меня установлена некоторые папки тестовых папок в этом пути файла, один из которых находится за пределами ограничения символов 260 PowerShell для включения.
Когда я запускаю этот код, PS запускает ошибку, сказав, что путь слишком длинный, а затем отображает конденсированную версию пути к файлу, имеющей проблему.Есть ли способ получить этот путь, чтобы я мог снова запустить код с длинным путем в объекте $ rootpath - чтобы он мог пойти глубже?
Решение
Чтобы получить имя короткого пути, которое вы можете использовать Get-ShortPath
из PowerShell Community Extensions (PSCX)
Вот одна из моих старой версии (я представляю, менее мощный)
# 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
}
}
}
.
gci 'C:\Program Files (x86)' | Get-MyShortPath
Get-MyShortPath 'C:\Program Files'
. Не связан с StackOverflow