【发布时间】:2019-04-15 11:46:25
【问题描述】:
正如标题所说,如果我尝试将-persist 添加到 cmdlt,它会返回错误:
New-PSDrive : The network resource type is not correct
At line:1 char:1
+ New-PSDrive -Name P -Root <redacted> ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
作为参考,这是 PowerShell 中的管理员会话,但如果我在常规用户会话中执行此操作,我会得到完全相同的响应:
PS> $PSVersionTable.psversion
Major Minor Build Revision
----- ----- ----- --------
5 1 16299 666
从一开始:我确认我要使用的驱动器号可用(在本例中为 P)
PS> get-psdrive
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
Alias Alias
C 36.80 22.11 FileSystem C:\ windows\system32
Cert Certificate \
D FileSystem D:\
Env Environment
Function Function
HKCU Registry HKEY_CURRENT_USER
HKLM Registry HKEY_LOCAL_MACHINE ...ntrol\NetworkProvider\Order
Variable Variable
WSMan WSMan
然后我尝试运行:(我已经将$locale 定义为变量,例如'\\foo\bar\')。
New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global
Name Used (GB) Free (GB) Provider Root CurrentLocation
---- --------- --------- -------- ---- ---------------
P FileSystem \\foo\bar\
快乐的日子。这样可行。但当然,它对 Windows 资源管理器是不可见的,因为它只是在这个 PS 会话中。所以,我销毁它(remove-psdrive P)并验证它已经消失(get-psdrive),这里没有显示,然后尝试创建一个持久版本(相同的命令,只是使用-persist):
PS> New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope global -Persist
New-PSDrive : The network resource type is not correct
At line:1 char:1
+ New-PSDrive -PSProvider FileSystem -Name P -Root $locale -Scope globa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (P:PSDriveInfo) [New-PSDrive], Win32Exception
+ FullyQualifiedErrorId : CouldNotMapNetworkDrive,Microsoft.PowerShell.Commands.NewPSDriveCommand
它失败了。对于上下文,我这样做是为了可以使用带有远程 PSDrive 的 RoboCopy 编写脚本(我们想要使用 robocopy,因为它内置了报告、属性管理以及在目标位置维护文件结构的能力,我们想要使用PSDrives,因此我们可以为目标驱动器指定凭据)。
有人有什么想法吗?
编辑: 哦,伙计……我不敢相信……但是以防万一其他人发现它,我将离开它。问题是我路径中的尾随\。我删除了它,它仍然很好。
【问题讨论】:
标签: powershell windows-scripting drive-mapping powershell-v5.1 new-psdrive