Powershell – Checking for Pirated Windows and Office Licenses

Checking for Pirated Windows and Office Licensing with Powershell

We just got a new non-profit client, and the old IT provider sold them hardware and charged for licenses, while using AutoKMS to falsely activate their Windows and Office licenses. Now I have to identify which machines are pirated and get new licenses purchased. The story of my life — cleaning up other people’s messes.

If you find yourself in a similar predicament, hopefully this code is helpful to you. I try to use single-liner code whenever I can, for reliability and ease of editing.

Because of the complexity of the text outputs — it can be extremely varied, I feel it is best to review the TXT files individually. I only have 70 machines to run through their TXT files. If you have thousands of files, well, at least the commands can get you the content.

This Powershell code will run on any Win7+ machine, and outputs a text file with the machine’s name and domain inside. The file is then copied to a temporary file-share I have made (everyone read/write), solely for the collection of these TXT files. Once they are collected, I will remove the share. Then I can ZIP up the TXT files, and pop everything into an Excel spreadsheet for providing a report to management on what to purchase. Just swap out “SERVERNAME\PUBLICHSHARE for your environment.

Enjoy!

#Save a TXT document for storing the license data, with the machine-name, and print the machine's name and domain into the TXT file.
echo $env:computername,$env:userdnsdomain | Out-File "\\SERVERNAME\PUBLICSHARE\LicensingCheck.$env:computername.txt"

#Echo the license statuses into the TXT file. Appending keeps the script from over-writing the file.
Get-CimInstance -ClassName SoftwareLicensingProduct | where PartialProductKey | select Name, LicenseStatus, LicenseFamily | FL | Out-File "\\SERVERNAME\PUBLICSHARE\LicensingCheck.$env:computername.txt" -append

#Write the licensing definitions into the text file.
echo "Definitions" "0 Unlicensed" "1 Licensed" "2 Out-Of-Box Grace Period" "3 Out-Of-Tolerance Grace Period" "4 Non-Genuine Grace Period" "5 Notification - Note that this includes Temporary Licensing Office 365, Student for 2 years, etc" "6 Extended Grace" | Out-File "\\SERVERNAME\PUBLICSHARE\LicensingCheck.$env:computername.txt" -append

Example Result File

COMPUTERNAME
CN.COMPANYNAME.COM

Name          : Office 15, OfficeO365ProPlusR_Subscription1 edition
LicenseStatus : 5
LicenseFamily : OfficeO365ProPlusR_Subscription1

Name          : Windows(R), Professional edition
LicenseStatus : 1
LicenseFamily : Professional

Name          : Office 15, OfficeStandardVL_MAK edition
LicenseStatus : 1
LicenseFamily : OfficeStandardVL_MAK


Definitions
0 Unlicensed
1 Licensed
2 Out-Of-Box Grace Period
3 Out-Of-Tolerance Grace Period
4 Non-Genuine Grace Period
5 Notification - Note that this includes Temporary Licensing Office 365, Student for 2 years, etc
6 Extended Grace

Leave a Reply

Your email address will not be published. Required fields are marked *