Remove License Key for Office 365

0

Hi all,

I am trying to edit a PowerShell working here to retrieve the installed product key for an Office 365 installation so I can then take that output and uninstall the key with ospp.vbs. But I cannot get the pipe to catch the output of the key and run it to uninstall it.

Any ideas?

This link has a code: https://community.spiceworks.com/how_to/48973-remove-and-re-add-license-key-for-office-2016-on-office-365

Here is the code:

#store the license info into an array
$license = cscript ‘C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS’ /dstatus
#license name from /dstatus
$o365 = “OfficeO365ProPlusR_Subscription1 edition”
#loop till the end of the array searching for the $o365 string 
for ($i=0; $i -lt $license.Length; $i++){
if ($license[$i] -match $o365){
$i += 6
#jumping six lines to get to the product key line in the array
$keyline = $license[$i]
#extra step
$prodkey = $keyline.substring($keyline.length – 5, 5)
#getting the last 5 characters of the line (prodkey)
} 
}
#removing the key from the workstation 
cscript ‘C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS’ /unpkey:$prodkey

Testing it on computer it runs but ends with: Unsupported command passed. A value is required for: /unpkey which means that the gathered data does not work putting it into $prodkey

Update: Import file can be downloaded in the bottom of the post.

Regards, Timmel

Cancel
login to comment
0

It looks like the script on Spiceworks had weird quote characters. Try this:

#store the license info into an array
$license = cscript 'C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS' /dstatus
#license name from /dstatus
$o365 = "OfficeO365ProPlusR_Subscription1 edition"
#loop till the end of the array searching for the $o365 string 
for ($i = 0; $i -lt $license.Length; $i++) {
    if ($license[$i] -match $o365) {
        $i += 6
        #jumping six lines to get to the product key line in the array
        $keyline = $license[$i]
        #extra step
        $prodkey = $keyline.substring($keyline.length – 5, 5)
        #getting the last 5 characters of the line (prodkey)
    } 
}
#removing the key from the workstation 
cscript 'C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS' /unpkey:$prodkey
Cancel
login to comment

0

Hi Colby, I figured it out!

Seems that it is not longer called OfficeO365ProPlusR_Subscription1 edition but Office16O365ProPlusR_Subscription1 edition. And lastly it needs to jump 7 rows.

Here is the correct code.

#store the license info into an array
$license = cscript 'C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS' /dstatus
#license name from /dstatus
$o365 = "Office16O365ProPlusR_Subscription1 edition"
#loop till the end of the array searching for the $o365 string 
for ($i = 0; $i -lt $license.Length; $i++) {
    if ($license[$i] -match $o365) {
        $i += 7
        #jumping seven lines to get to the product key line in the array
        $keyline = $license[$i]
        #extra step
        $prodkey = $keyline.substring($keyline.length – 5, 5)
        #getting the last 5 characters of the line (prodkey)
    } 
}
#removing the key from the workstation 
cscript 'C:\Program Files (x86)\Microsoft Office\Office16\OSPP.VBS' /unpkey:$prodkey

End result was:

Uninstalling product key for: Office 16, Office16O365ProPlusR_Subscription1 edition

If someone wants the code and import it into PDQ Inventory as a Tool, I have sent it to support@pdq.com. Maybe they can attach it in the post? Doesn't look like I have that option...

Regards, Martin

Awesome, I'm glad you were able to figure it out! Unfortunately, the only files that can be attached to posts are images. If you want to share the XML file of the Tool you created, I recommend uploading it to something like Pastebin or gist.github.com.

Cancel
login to comment

0

If intereted file can be downloaded here: Reset Office 365 Key on Client

Cancel
login to comment

Reply