'Powershell: how do I get the current volume as a single letter [duplicate]
I would like to have the current volume name as part of a filename, e.g. bsps-on-c.txt for files in volume C:, bsp-on-d.txt for files in volume d and so on.
code is:
$v=volume
$col=@{expression="driveletter";label=""}
$v | where {$_.drivetype -like "Fixed" -and $_.driveletter -notlike "" } | format-table $col
output is:
-
C
question is: How to get rid off empty lines and line with -
Expectation was:
only letter C and nothing more, no white spaces, no empty lines
Solution 1:[1]
If you just want to output the drive letter on its own:
Get-Volume |Where-Object {$_.DriveType -like "Fixed" -and $_.DriveLetter -notlike "" } |ForEach-Object DriveLetter
ForEach-Object DriveLetter will attempt to resolve the DriveLetter property on each input object and return its raw value.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mathias R. Jessen |
