0

I have a BAT file with the following:

wmic diskdrive get serialnumber > test.txt

It almost works, but the command has an issue when manufacturers entered the serial number in Hex. For instance drive serial on HD is abc123 the output given is ba1c32, so every pair is flipped. I will use the same model laptops/Hard drives so the input is guaranteed to stay constant.

Is there any way to edit the output to correct this issue so the text.txt file has the correct serial number? I cannot use outside scripting (this would be so easy in python/VBA), everything has to be done through the command prompt/batch file.

Any help is greatly appreciated. Thanks in advance.

rojo
  • 24,000
  • 5
  • 55
  • 101
  • 1
    possible duplicate of [WMIC Returning Odd Serial Number](http://stackoverflow.com/questions/27297348/wmic-returning-odd-serial-number) – rojo Jun 03 '15 at 15:32
  • 1
    Short answer: `powershell "gwmi win32_diskdrive | %{ $_.serialnumber -replace '(.)(.)','$2$1' }" > test.txt` – rojo Jun 03 '15 at 15:47
  • I tried using that script but in my file I get - At line:1 char:24 + gwmi win32_diskdrive | { $_.serialnumber -replace '(.)(.)','$2$1' } + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Expressions are only allowed as the first element of a pipeline. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordEx ception + FullyQualifiedErrorId : ExpressionsMustBeFirstInPipeline – Kurz Reido Jun 03 '15 at 19:51
  • If you're putting this in a batch script, you probably need to double-pump the `%` sign. `powershell "gwmi win32_diskdrive | %%{ etc.` – rojo Jun 03 '15 at 20:20
  • You are the man! Thank you! :D – Kurz Reido Jun 03 '15 at 23:04

0 Answers0