Batch – Return Serial Number of Certificate.cer File

email me

How to return the serial number of a certificate, so it can be used by certutil.


setlocal enabledelayedexpansion
set count=1
set var=

for /f "tokens=* delims=:" %%a in ('certutil c:\YourCert.cer') do (
if !count!==3 set var=%%a
set /a count+=1

for /f "tokens=2 delims=:" %%b in ("%var%") do set serial=%%b

set serial=%serial: =%

certutil -exportPFX -p "YourPassword" my %serial% c:\YourCert.pfx


certutil -p YourPassword -exportPFX %computername% C:\YourCert.pfx