- It seems that it takes the actual serial number and reverses every two characters; Am I typing something wrong or is this a known (but not documented) problem?
The best I can understand is apparently a mistake . My characters also pair up, and it's not limited to wmic. Same result if I SELECT SerialNumber FROM Win32_DiskDrive from winmgmts:\\localhost\root\cimv2 in WSH.
βIs there a way I can take a variable, split it into two parts of characters, reorder all of these characters, and then put it in a variable?β
If you have PowerShell installed, you can do this with regexp replace . Here's the script package that invokes the PowerShell command to demonstrate:
@echo off setlocal for /f "tokens=*" %%I in ('wmic diskdrive get serialnumber ^| findstr "[0-9]"') do ( echo reversed: %%I for /f "tokens=*" %%x in ('powershell -command "'%%I' -replace '(.)(.)','$2$1'"') do ( set "serial=%%x" ) ) echo corrected: %serial% goto :EOF
I guess this qualifies as a duck punch . :)
In fact, if you just want to see the serial number without setting a variable, you can do this with a single-line PowerShell file:
powershell "gwmi win32_diskdrive | %{ $_.serialnumber -replace '(.)(.)','$2$1' }"
source share