Search code examples
powershellvisual-studio-codepowershell-5.0powershell-7.0

Why does VS Code PowerShell terminal map a new drive?


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.

Fig 1.1

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:

Fig 1.2 Windows Terminal PowerShell 5.1

Fig 1.3 PowerShell 5.1

Fig 1.4 PowerShell 5.1 (86x)

Fig 1.5 PowerShell 7 (86x)

Fig 1.6 Windows Terminal PowerShell 7


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?


Solution

  • 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.