Unable to change drive letter using Win32_volume

Hi

I start Subst K: D:\Application

But the script below does not work if i will change the drive letter

$NewDriveLetter = Get-ChildItem function:[L-Z]: -n | ?{ !(test-path $_) } | Select-Object -First 1

Get-WmiObject -Class Win32_volume -Filter "DriveLetter = 'k:'" | Set-WmiInstance -Arguments @{ DriveLetter = $NewDriveLetter };
Write-Host "Mapping k:\ drive..."
start-process subst "k: $env:TEMP"

Is there any another option with Powershell / WMI class?

What is

Subst K: D:\Application

Can you tell us what are you trying to acheive with the above code ?

See

https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/subst

thanks for the link. Does the above code throws any error for you or it just executes doing nothing ?

Note that WQL filters are case sensitive, make sure the drive letter k is small, IMO, it should be in upper case.

Hi,

Get-WmiObject -Class Win32_volume -Filter “DriveLetter = ‘k:’” | Set-WmiInstance -Arguments @{ DriveLetter = $NewDriveLetter };

it just executes but doing nothing

Make sure Get-WmiObject -Class Win32_volume -Filter “DriveLetter = ‘k:’” returns the result for Set-WMIINstance to set.

I suggest using CIM over WMI.

  • Get-CIMInstance
  • Set-CIMInstance