every now and then Windows (10) will swap the assigned drive letters of my 2 attached usb type 3 devices. So instead of having J: with a label "keedrive" and V: with a label "secondary", Windows will sometimes swap them, J: becomes "secondary" and V: "keedrive". I'm trying to have a Batch script that will check if the drives letter have changed and if so reset them as they were.
Currently, i have to manually re-assign the letters with Diskpart utility.
I have read about How to run a PowerShell script from a batch file and How do I capture the output into a variable from an external process in PowerShell, trying to get a working script. So far i bogged at the level of getting the output of a PowerShell command into a variable, not knowing how to set the condition for checking the drive letters based on the DeviceID and subsequently re-assign the letters accordingly. Please help. In advance thank you.
Here is the PowerShell commands i came up with
Get-CimInstance -ClassName CIM_StorageVolume | Format-Table -Property DeviceID, DriveLetter, Label | Tee-Object -variable UsBDrvLetters