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
Question
Mike Lynch 0
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
Any recommendations for a supported alternative?
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.