powershell - 从映射的网络驱动器检索文件时出错
问题描述
我在 PowerShell 中创建了一个映射的网络驱动器,但是在从驱动器中检索文件时有一些奇怪的行为。当我创建驱动器(不带-Persist -Scope Global
)时:
$somePath = "\\testtest.lan\Res\Application\TestApp\SomeFiles"
$PsDrive = New-PSDrive -Name "M" -PSProvider "FileSystem" -Root $somePath
Get-ChildItem "M:\" -Recurse | Select-Object -Property *, @{n='Path';e={$_.FullName -replace [regex]::Escape("M:\")}}
在我第一次尝试Get-Child
如上所述做时,我收到一条错误消息:
“Get-ChildItem:长度不能小于零”
在我第二次尝试时,它工作得很好,我可以看到列出的所有文件。下次我尝试它会停止工作(在同一会话中)并出现不同的错误:
Get-ChildItem:发生意外的网络错误。
在 line:1 char:1
+ Get-ChildItem "M:\" -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (\testtest.l..er\Res\Application\TestApp\SomeFiles:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
当我尝试像这样创建映射的网络驱动器时:
New-PSDrive -Name "M" -PSProvider "FileSystem" -Root $somePath -Persist -Scope Global
它会立即工作几次,但它会在一段时间后停止工作,并出现与上述相同的错误:
Get-ChildItem:发生意外的网络错误。
在 line:1 char:1
+ Get-ChildItem "M:\" -Recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ReadError: (\testtest.l..er\Res\Application\TestApp\SomeFiles:String) [Get-ChildItem], IOException
+ FullyQualifiedErrorId : DirIOError,Microsoft.PowerShell.Commands.GetChildItemCommand
当我这样做时,Get-PsDrive
我可以在那里看到映射的驱动器。
我是在代码中做错了什么,还是我尝试访问的网络位置有问题。它不应该与权限相关,因为有时它可以正常工作,或者可能是。当我从文件资源管理器尝试时,我能够访问网络位置。
让我知道你对此的看法。
谢谢,
安德烈
解决方案
推荐阅读
- c++ - 常用表达。搜索不重复数字的单词
- android - Firebase UI Phone Auth Spinner 样式
- sql - 交叉销售矩阵 - 在雪花中
- allennlp - AllenNLP:如何知道输出张量的哪个索引对应于哪个类
- php - php-html-parser 如何跟踪重定向
- spring - Spring OAuth2 客户端多租户
- typoscript - 在 f:cObject 的 where 子句中使用两列的更简单方法?
- python - ValueError:对象类型系列没有名为 1 的轴
- file - 我在nodejs中创建了一个静态文件夹,但是当虚拟路径深度嵌套时无法为其创建虚拟路径前缀
- ios - AVComposition 中的preferredTransform 不正确