3

我在 Visual Studio Code 中制作了一个使用 command 的 PowerShell 脚本,Get-PSDrive令我惊讶的是,在使用 VS Code 时,似乎出现了一个与我的C:\驱动器相同的新驱动器Temp

图 1.1

据我所知,这个结果让我大吃一惊,除了我的主C:\驱动器外,我只连接了 2 个其他驱动器。我试图在其他终端上复制它但没有成功,除了 PowerShell 7:

图 1.2 Windows 终端 PowerShell 5.1

图 1.3 PowerShell 5.1

图 1.4 PowerShell 5.1 (86x)

图 1.5 PowerShell 7 (86x)

图 1.6 Windows 终端 PowerShell 7


当我看到它被 PwSh 7 复制时,我决定使用$host变量检查每个 PowerShell 的版本,我看到了更意想不到的东西:

Version          : 5.1.19041.1

Windows 终端 PowerShell 5.1

Version          : 5.1.19041.1

PowerShell 5.1

Version          : 5.1.19041.1

PowerShell 5.1 (86x)

Version          : 7.0.2

PowerShell 7 (86x)

Version          : 7.0.2

Windows 终端 PowerShell 7

这一切看起来都很正常,但是当我检查 VSCode 时$host,我得到了结果

Version          : 2020.6.0

是什么导致输出的差异

Get-PSDrive | Where-Object {$_.Provider.Name -eq "FileSystem"}

在 PwSh 7、PowerShell 5.1 和 VS Code PwSh 之间?

4

1 回答 1

6

Temp:驱动器不是“与我的驱动器相同的新驱动C:\器”;它Root$Env:Temp,不是C:\

根据实际描述 PowerShell 7.1 的PowerShell Team May 2020 Update,这是在 PowerShell 7.0 中添加的...

在 PowerShell 7.0 中,我们添加了temp:PSDrive。这适用于所有平台并自动映射到您的用户临时路径。

顺便说一句,您用来制作这些屏幕截图的命令可以简化为Get-PSDrive -PSProvider FileSystem.

于 2020-07-07T21:29:22.603 回答