Jump to content
  • 0

Alternative to wmic volume get driveLetter, label ?


Mike Lynch

Question

I just upgraded to 24H2 and discovered that WMIC has been removed from Windows. I now have a bunch of dead maintenance batch files. I've re-added WMIC "Feature on Demand" to one computer but that's a temporary fix. Microsoft recommends converting to Powershell but I don't know PS and am likely to make matters worse. I might be able to convert the one subroutine bat file that contains the WMIC if the other .bat files can invoke a PS script and if PS can return a "global" variable that can be picked up by a .bat file. I would rather find a function that can be used in the .bat subroutine.

The subroutine looks for all drives with labels starting with a specific string. If there is only one, it returns the drive letter in a global variable. If there is none or more than one the script complains until the user makes sure there is only one.

The chunk of code (not the entire script) containing the WMIC command is
Code:
@echo off
SETLOCAL
:Test
:: Find a drive with label containing "SBD MM #"
:: Ignore the drive containing this script

Set LabelMask=SBD MM #

Set Drive=
Set Extra=
Set Here=%~d0%

for /f %%D in ('wmic volume get DriveLetter^, Label ^| find /I "%LabelMask%" ^| find /V "%Here%"') Do (
   if defined Drive set Extra=%%D
   if not defined Drive set Drive=%%D
   )
If "%Drive%"=="" GoTo NoFlash
If not "%Extra%"=="" GoTo DupDrive
GoTo Return

Any recommendations for a supported alternative?
 
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • AD
  • Recent Status Updates

    No Recent Status Updates
  • Most Solved

    Nothing has been solved this week.

×
×
  • Create New...