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
As I saw that it was replicated by PwSh 7, I decided to check the versions of each of the PowerShells with the $host
variable and I saw something even more unexpected:
Version : 5.1.19041.1
Windows Terminal 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 Terminal PowerShell 7
which all seemed normal, but when I checked the VSCode $host
, I got the result
Version : 2020.6.0
What is causing the differences in the outputs of
Get-PSDrive | Where-Object {$_.Provider.Name -eq "FileSystem"}
between PwSh 7, PowerShell 5.1, and VS Code PwSh?
That Temp:
drive is not "a new drive identical to my C:\
drive"; its Root
is $Env:Temp
, not C:\
.
According to PowerShell Team May 2020 Update, which actually describes PowerShell 7.1, this was added in PowerShell 7.0...
In PowerShell 7.0, we added a
temp:
PSDrive. This works on all platforms and automatically maps to your user temporary path.
By the way, the command you used to make those screenshots could be simplified to Get-PSDrive -PSProvider FileSystem
.