Hello! I have a section of one script that gets the last 5 of the installed product key. The goal is to run it on all machines to get an inventory of Office licenses. It works great but sometimes the output of
cscript "C:\Program Files\Microsoft Office\Office16\OSPP.VBS" /dstatus
will contain multiple entries (i.e. when the user had a grace period). In that case there will be two entries... The current license and the grace period license. If the grace period is present, the script grabs that instead of the actual license. I've played around with it but can't figure out how to stop it from getting the grace period license. Any suggestions?
Code:
@echo off
for /f "tokens=2 delims=:" %%G IN ('cscript "C:\Program Files\Microsoft Office\Office16\OSPP.VBS" /dstatus ^| findstr /C:"Last 5 characters of installed product key:"') do ( set "key=%%G" )
set "key=%key: =%"
echo %key%