PowerShell 5.0 PathTooLongException 错误 [英] PowerShell 5.0 PathTooLongException Error

查看:33
本文介绍了PowerShell 5.0 PathTooLongException 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

正在接收 PathTooLongException - ... 完全限定的文件名必须少于 260 个字符,并且目录名必须少于 248 个字符.

Receiving PathTooLongException - ... fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

操作系统

  • Windows Server 2008 R2 企业版

PowerShell 版本

  • PS 版本 5.1.14409.1018
  • 构建版本 10.0.14409.1018
  • CLR 版本 4.0.30319.36543
  • WSManStack 版本 3.0
  • PSRemotingProtocolVersion 2.3
  • 序列化版本 1.1.0.1

.NET 框架版本

  • 4.5.51209

代码

Get-ChildItem -Path $path -Directory -Recurse | Get-ACL
ForEach ($item in $pathmany) {
        $permissions = $item.access | where {$_.IdentityReference -like "*$target*"}
        $permissions.FullPath | where {$_.IdentityReference -like "*$target*"}
        if ($permissions.IdentityReference -like "*$target*") {
            $path = $item.Path.trim('Microsoft.PowerShell.Core\FileSystem::')
        }
}

到目前为止我尝试过的

1 - 设置位置进一步进入文件夹树"(错误)

1 - Set-Location "further into folder tree" (error)

2 - Subst TEMP文件夹进一步进入文件夹树"(错误)

2 - Subst TEMP "folder further into folder tree" (error)

3 - \计算机名称\进一步进入文件夹树的文件夹"\(错误)

3 - \computer name\"folder further into folder tree"\ (error)

4 - 使用 2019 服务器,我可以在其中将注册表编辑为LongPathsEnabled = 1"我也尝试使用 \?\UNC\ 方法,但它返回了相同的错误.

4 - Using a 2019 server where I can edit the registry to "LongPathsEnabled = 1" I also tried to use the \?\UNC\ method and it returned the same error.

也试过这个代码还是报错

Also tried this code and still get the error

$folder = @{ Name = "\\?\UNC"}
$folder.path = "folder further into folder tree"

$folder | ForEach-Object {
     $item = Get-ChildItem -Path $_.Path -Directory -Recurse | Get-ACL
}

询问我的主管是否可以升级到 PowerShell 6.0 或 7.0.

Asking my supervisor if an upgrade to PowerShell 6.0 or 7.0 is doable.

任何帮助或想法将不胜感激.

Any help or ideas will be appreciated.

推荐答案

我在 PowerShell 7 中使用上述脚本,并且代码能够检索出现 LongPathException 错误的文件夹.但是,我收到一个新错误,我将针对该错误发布另一个问题.我能够想出并解决我的问题的答案如下.我能够计算文件夹树中的 145,000 多个文件夹L:\Depts.

I am using the above script with PowerShell 7 and the code is able to retrieve the folders where I was getting the LongPathException error. However, I am getting a new error that I will post a another question for. The answer I was able to come up with and works for my problem is as follows. I was able to count 145,000+ folders in the folder tree L:\Depts.

脚本问题错误

Get-ChildItem -Path "L:\Depts" -Directory -Recurse

安装 PowerShell 7.0 将更正错误

Install PowerShell 7.0 will correct the error

Get-ChildItem : The specified path, file name, or both are too long. The fully
qualified file name must be less than 260 characters, and the directory name must
be less than 248 characters.

这篇关于PowerShell 5.0 PathTooLongException 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆