在长路径名上获取文件夹 NTFS ACL

编程入门 行业动态 更新时间:2024-10-10 04:21:23
本文介绍了在长路径名上获取文件夹 NTFS ACL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 PS 脚本,如果分配了单个用户,它将返回 NTFS ACL,运行良好,直到我遇到超过 260 个字符的路径.我发现了很多关于路径太长问题和一些变通方法的信息,但我正在努力将解决方案集成到我的脚本中.有什么建议吗?

I have a PS script that will return NTFS ACLs if an individual user is assigned, works well until I hit a path exceeding 260 characters. I've found a lot of information on the path too long problem and some work-arounds but I'm struggling to integrate a solution into my script. Any suggestions?

谢谢!

$DateStart = Get-Date $Path = "E:\" $PermittedOU1 = "OU=Groups,dc=chiba,dc=localt" $PermittedOU3 = "OU=System Accounts,OU=Accounts,dc=chiba,dc=local" $PermittedACL1 = get-adgroup -Filter * -SearchBase $PermittedOU1 $PermittedACL3 = get-aduser -Filter * -SearchBase $PermittedOU3 $ObjectPathItem = Get-ChildItem -path $Path -Recurse | where-object {$_.PsIsContainer} | foreach- object -process { $_.FullName } $howmany=0 $Logfilename = "C:\Users\administrator\Documents\$(get-date -f yyyy-MM-dd-hh-mm).csv" Add-Content $Logfilename "$DateStart`n" $totalfolders=0 $i=0 ForEach ($Folder in $ObjectPathItem) { $totalfolders++ } Foreach ($Folder in $ObjectPathItem) { $ObjectACL = Get-ACL -Path $Folder $i++ $howmany=0 Write-Progress -id 1 -Activity "Folder Recursion" -status "Folders Traversed: " -PercentComplete (($i / $totalfolders) * 100) Foreach ($ACL in $ObjectACL.access) { $ACLstring = $ACL.identityreference.Value $ACLstring = $ACLstring.Replace("CHIBA\","") if (($ACLstring -notin $PermittedACL1.name)` -and ($ACLstring -notin $PermittedACL3.SamAccountName)` -and ($ACLstring -notin "NT AUTHORITY\SYSTEM") ` -and ($ACLstring -notin "BUILTIN\Administrators") ` -and ($ACLstring -notin "CREATOR OWNER")) { $newline = "`"$Folder`"" + "," + "$ACLString" Add-Content $Logfilename "$newline" $howmany+=1 } else { $howmany+=1 } } } $DateEnd = Get-Date Add-Content $Logfilename "`n`n$DateEnd"

推荐答案

您通常可以使用的一个选项是使用 New-PSDrive 创建映射驱动器.类似的东西:

One option you can usually use is to create a mapped drive using New-PSDrive. Something like:

Try{ $ObjectACL = Get-ACL -Path $Folder } Catch{ $SubPathLength = $Folder.FullName.substring(0,200).LastIndexOf('\') $NewTempPath = $Folder.FullName.SubString(0,$SubPathLength) New-PSDrive -Name Temp4ACL -Provider FileSystem -Root $NewTempPath $ObjectACL = Get-ACL "Temp4ACL:$($Folder.FullName.SubSTring($SubPathLength,$Folder.FullName.Length-$SubPathLength))" }

这将找到路径中第 200 个字符之前的最后一个 \,抓取完整路径的子字符串直到该文件夹​​名称的末尾并创建它的临时驱动器,然后获取基于临时驱动器和剩余路径的 ACL.所以这条路:

That will find the last \ before the 200th character in the path, grab a substring of the full path up to the end of that folder's name and create a temp drive of it, then get the ACL based off the temp drive and the remaining path. So this path:

C:\Temp\Subfolder\Really Long Folder Name\Another Subfolder\ABCDEFGHIJKLMNOPQRSTUVWXYZ\We Are Really Pushing It Now\Im Running Out Of Folder Name Ideas\Hello My Name Is Inigo Montoya\You Killed My Father Prepare To Die\ReadMe.txt

在倒数第二个反斜杠处被剪切.我最终会从以下位置获得 ACL:

Gets cut at the second to last backslash. I would end up getting the ACL from:

Temp4ACL:\You Killed My Father Prepare To Die\ReadMe.txt

更多推荐

在长路径名上获取文件夹 NTFS ACL

本文发布于:2023-11-28 10:53:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642105.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   路径   ACL   NTFS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!