I have the following statement
$Volname='PATRIOT' Get-PSDrive | Where-object Description -eq $Volname | Write-host
I mount an external USB flash drive to satisfy the $Volname and it correctly returns the drive letter (H, I, whatever). This is on a Windows 7 (64-bit) PC.
I take this exact same line of code to a Windows 10 PC and it fails here because the Get-PSDrive worked differently: the Description field here returned blanks. The objective is to extract the mapped drive letter based on the volume name (label) of the mounted disc. It is assumed the volume name (label) is unique insofar as the PC it is mounted to is concerned, i.e., no duplicates.
As far as getting something “that works on both Win7 and Win10” goes, I’ve reverted to using Get-CIMinstance. I am just wondering why Get-PSDrive works differently on Win7 / Win10. Both Windows PCs were running Powershell 5.1 ISE.
Would be grateful if someone can shed some light on this behavior.
Thanks in advance.