3

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?

Nico Nekoru
  • 2,840
  • 2
  • 17
  • 38
  • the `$Host` variable is NOT necessarily the version of PoSh/Pwsh. it's the host/console info and is _usually_ the ps version. you may want to cross-check the `.Version` with the `.Name`. ///// my PS7 install shows that `Temp:` drive in the console AND in the VSCode console. i presume it is something that PS7 does by default. i suspect it is a convenience feature to deal with different ways to find the OS/user temp dir. – Lee_Dailey Jul 07 '20 at 21:14
  • I took this from the `Version` section in the `$host` variable – Nico Nekoru Jul 07 '20 at 21:17
  • 1
    yep, and that is not _always_ the PoSh/Pwsh version number. _sometimes_ it will be the just the console host version. you are safer to use `$PSVersionTable` for the PS version. – Lee_Dailey Jul 07 '20 at 21:28
  • 2
    according to this >>> Provide a platform-agnostic way to determine the temp. directory, e.g., via an automatic variable. · Issue #4216 · PowerShell/PowerShell — https://github.com/PowerShell/PowerShell/issues/4216 <<< it seems to be something added with ps7 to give coders a consistent way to find the actual temp dir. – Lee_Dailey Jul 07 '20 at 21:29

1 Answers1

6

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.

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68