How do we get a drive by its label in PowerShell 5.0?
I did a little more research and came up with this little snippet:
To answer #1:
$scriptDrive = Get-Volume -FileSystemLabel MasterSword
To answer #2:
$scriptDriveLetter = $scriptDrive.DriveLetter
And together, they would be:
$scriptDrive = Get-Volume -FileSystemLabel MasterSword
$scriptDriveLetter = $scriptDrive.DriveLetter
Or for another interpretation:
$scriptDriveLetter = (Get-Volume -FileSystemLabel MasterSword).DriveLetter
Where the necessary drive letter is stored in $scriptDriveLetter
.
You could try:
Get-PSDrive | Where-Object {$_.Description -eq "MasterSword"}
This will return an object such as:
Name : E
Description : MasterSword
Provider : Microsoft.PowerShell.Core\FileSystem
Root : E:\
CurrentLocation : Scripts
Thus, assuming your scripts are in the "Scripts" folder, you can find them with:
$Root = (Get-PSDrive | Where-Object {$_.Description -eq "MasterSword"}).Root
$Path = Join-Path $Root "Scripts"