Nic*_*oru 3 powershell powershell-5.0 visual-studio-code powershell-7.0
I was making a PowerShell script in Visual Studio Code that used the command Get-PSDrive, and to my surprise, it seemed like while using VS Code, a new drive identical to my C:\ drive called Temp appeared.
I was taken aback by this result as as far as I knew, I only had 2 other drives besides my main C:\ drive connected. I tried to replicate this on other terminals with no success except for PowerShell 7:
Windows Terminal PowerShell 5.1
当我看到它被 PwSh 7 复制时,我决定用$host变量检查每个 PowerShell 的版本,我看到了更意想不到的东西:
Version : 5.1.19041.1
Run Code Online (Sandbox Code Playgroud)
Windows 终端 PowerShell 5.1
Version : 5.1.19041.1
Run Code Online (Sandbox Code Playgroud)
PowerShell 5.1
Version : 5.1.19041.1
Run Code Online (Sandbox Code Playgroud)
PowerShell 5.1 (86x)
Version : 7.0.2
Run Code Online (Sandbox Code Playgroud)
PowerShell 7 (86x)
Version : 7.0.2
Run Code Online (Sandbox Code Playgroud)
Windows 终端 PowerShell 7
这一切看起来都很正常,但是当我检查 VSCode 时$host,我得到了结果
Version : 2020.6.0
Run Code Online (Sandbox Code Playgroud)
是什么导致了输出的差异
Get-PSDrive | Where-Object {$_.Provider.Name -eq "FileSystem"}
Run Code Online (Sandbox Code Playgroud)
在 PwSh 7、PowerShell 5.1 和 VS Code PwSh 之间?
该Temp:驱动器不是“与我的C:\驱动器相同的新驱动器”;它Root是$Env:Temp,不是C:\。
根据PowerShell Team May 2020 Update,它实际上描述了 PowerShell 7.1,这是在 PowerShell 7.0 中添加的...
在 PowerShell 7.0 中,我们添加了一个
temp:PSDrive。这适用于所有平台并自动映射到您的用户临时路径。
顺便说一下,您用来制作这些屏幕截图的命令可以简化为Get-PSDrive -PSProvider FileSystem.
| 归档时间: |
|
| 查看次数: |
62 次 |
| 最近记录: |