Hi All,
I hope this message finds you in good spirits.
Recently, I've been looking into a way to remotely fetch Windows product keys for multiple workstations using batch file. Through my research, I came across the WMIC command, which seems good. and need to extract these keys from a list of computer names in a text file and save them to an output text file, all in one go, but unfortunately it didn't work
here is the code that i used :
@echo off
setlocal EnableDelayedExpansion
set "inputFile=input.txt"
set "outputFile=output_WPK.txt"
for /f "delims=" %%A in (%inputFile%) do (
set "computerName=%%A"
echo Product Key for !computerName!: >> %outputFile%
for /f "tokens=2 delims==" %%I in ('wmic /node:!computerName! path softwarelicensingservice get OA3xOriginalProductKey /value') do (
echo %%I >> %outputFile%
)
echo. >> %outputFile%
)
echo Product Keys extracted and saved to %outputFile%
pause
And here the output data below
Product Key for C3I-PC1:
ECHO is off.
Product Key for C3I-PC2:
ECHO is off.
Product Key for C3I-PC3:
ECHO is off.
And i want to exetract the Computer name and product key Only under each other like that
[ ComputerName : Windows Product Key]
[ ComputerName : Windows Product Key]
Your expertise in this area would be immensely helpful. If you have any tips, best practices, or perhaps even a sample script, I'd be extremely grateful.
Thank you so much for your efforts
Warm regards,