如何在 PowerShell 中将位置设置为映射的网络驱动器?

Sam*_*mir 7 networking windows-7 powershell

我正在尝试在 PowerShell 中将位置设置为映射的网络驱动器 Z,但它不起作用。

我有以下驱动器号:C、D、E、Z。其中前三个只是本地磁盘,Z 当然是映射到字母 Z 的网络位置。

我可以从C切换到D,再到E,再回到C,但出于上帝的爱,我不能出于某种原因切换到Z字母。但是我可以切换到那个位置,但是我必须输入网络位置而不是使用驱动器号。

PS C:\Windows\system32> D:
PS D:\> C:
PS C:\Windows\system32> Z:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<<  Z:
    + CategoryInfo          : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32> Set-Location \\fileserver\karta
PS Microsoft.PowerShell.Core\FileSystem::\\fileserver\karta> C:
PS C:\Windows\system32> Z:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<<  Z:
    + CategoryInfo          : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32> Set-Location Z:
Set-Location : Cannot find drive. A drive with the name 'Z' does not exist.
At line:1 char:13
+ Set-Location <<<<  Z:
    + CategoryInfo          : ObjectNotFound: (Z:String) [Set-Location], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SetLocationCommand

PS C:\Windows\system32>
Run Code Online (Sandbox Code Playgroud)

一种

为什么它不起作用?这在 PowerShell 中是否不受支持...使用驱动器号将位置设置为网络位置?

Ƭᴇc*_*007 13

您遇到的问题是因为Z:驱动器是在您的用户上下文中映射的,而不是在“管理员”上下文中。

因此,当您以“管理员身份”运行 PowerShell 时,Z: 驱动器(映射)不存在,如果需要,您必须在该上下文中创建它才能使用。