Powershell alert for windos activation

%3CLINGO-SUB%20id%3D%22lingo-sub-814341%22%20slang%3D%22en-US%22%3EPowershell%20alert%20for%20windos%20activation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-814341%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20everyone%2C%3C%2FP%3E%3CP%3EI%20need%20someone%20to%20help%20me%20to%20create%20an%20alert%20if%20my%20windows%20licence%20key%20is%20deactivated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-814341%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-848294%22%20slang%3D%22en-US%22%3ERe%3A%20Powershell%20alert%20for%20windos%20activation%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-848294%22%20slang%3D%22en-US%22%3E%3CP%3EHello%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F395204%22%20target%3D%22_blank%22%3E%40tonnybabs%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20created%20a%20script%20which%20you%20can%20use%2C%20but%20you%20will%20probably%20have%20to%20edit%20it%20since%20I%20don't%20know%20what%20kind%20of%20licensing%20are%20you%20using.%20For%20example%20if%20you%20use%20Education%20License%20you%20will%20have%20to%20change%20the%20parameter%20in%20the%20script%20inside%20the%20'where'%20condition.%20I%20will%20shortly%20explain%20how%20can%20you%20navigate%20through%20the%20PowerShell%20to%20get%20the%20information%20you%20need%20and%20send%20a%20notification%20via%20e-mail.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20before%20we%20begin%20I%20would%20recommend%20a%20short%20reading%20about%20windows%20license%20types%3A%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fsecureinfra.blog%2F2019%2F01%2F13%2Funderstanding-volume-activation-services-part-1-kms-and-mak%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fsecureinfra.blog%2F2019%2F01%2F13%2Funderstanding-volume-activation-services-part-1-kms-and-mak%2F%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBasically%20what%20you%20need%20to%20do%20is%20to%20find%20out%20what%20you%20want%20to%20monitor%20with%20your%20script%2C%20for%20example%20in%20my%20script%20we%20will%20be%20monitoring%20Windows%20Operating%20System%20license%2C%20Enterprise%20Edition%2C%20Volume_KMSClient%20license%20family.%3C%2FP%3E%3CP%3EFirstly%20to%20get%20familiar%20with%20the%20output%20of%20the%20cmdlet%20I%20would%20recommend%20trying%20to%20execute%20this%20cmdlet%3A%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3EGet-CimInstance%20-ClassName%20SoftwareLicensingProduct%20-ComputerName%20%24env%3ACOMPUTERNAME%20%7C%20where%20%7B%24_.Description%20-eq%20%22Windows(R)%20Operating%20System%2C%20VOLUME_KMSCLIENT%20channel%22%7D%20%7C%20select%20description%2Clicensefamily%2Clicensestatus%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CU%3E%3CEM%3ENote%3A%20change%20the%20%22Windows(R)%20Operating%20System%2C%20VOLUME_KMSCLIENT%20channel%22%20with%20the%20licensing%20you%20use.%3C%2FEM%3E%3C%2FU%3E%3C%2FP%3E%3CP%3EWith%20that%20output%20you%20should%20get%20license%20status%20of%20the%20VOLUME_KMSCLIENT%20channel%20license%20family%20(or%20any%20other%20license%20family%20you%20use).%20With%20that%20cmdlet%20you%20will%20get%20more%20familiar%20of%20what%20you%20need%20and%20why%20is%20the%20script%20written%20the%20way%20it%20is.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3E%24LicenseTest%20%3D%20Get-CimInstance%20-ClassName%20SoftwareLicensingProduct%20-ComputerName%20%24env%3ACOMPUTERNAME%20%7C%20where%20%7B%24_.Description%20-eq%20%22Windows(R)%20Operating%20System%2C%20VOLUME_KMSCLIENT%20channel%22%20-and%20%24_.LicenseFamily%20-eq%20%22Enterprise%22%7D%20%7C%20select%20-ExpandProperty%20licensestatus%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%3CEM%3E%3CSTRONG%3Eif(%24LicenseTest%20-inotlike%20%221%22)%7B%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3ESend-MailMessage%20-SmtpServer%20%22YourSmtpServer%22%20-From%20%22AddressYouWantToSendItFrom%22%20-To%20%22AddressYouWantToNotify%22%20-Body%20%22%24(%24env%3ACOMPUTERNAME)%20%7C%20Not%20Licensed%22%20-Subject%20%22LicenseStatus%22%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%7D%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3Eelse%7B%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3ESend-MailMessage%20-SmtpServer%20%22YourSmtpServer%22%20-From%20%22AddressYouWantToSendItFrom%22%20-To%20%22AddressYouWantToNotify%22%20-Body%20%22%24(%24env%3ACOMPUTERNAME)%20%7C%20Is%20Licensed%22%20-Subject%20%22LicenseStatus%22%3C%2FSTRONG%3E%3C%2FEM%3E%3CBR%20%2F%3E%3CEM%3E%3CSTRONG%3E%7D%3C%2FSTRONG%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%20if%20you%20need%20it%20for%20more%20computers%20than%20one%20you%20can%20use%20foreach%20and%20load%20of%20list%20of%20computers%20in%20order%20to%20do%20this%20for%20every%20single%20one%20in%20the%20list%2C%20but%20if%20doing%20so%20I%20would%20recommend%20saving%20information%20in%20variable%20and%20than%20storing%20in%20.csv%20or%20.txt%20and%20send%20the%20file%20via%20mail%20(otherwise%20you%20will%20get%20spammed%20for%20every%20computer%20inspected%20with%20separated%20mail%20message).%3C%2FP%3E%3CP%3EDon't%20forget%20to%20read%20the%20script%20and%20replace%20with%20the%20data%20you%20need%2C%20copy%2Fpaste%20%3CSTRONG%3Ewill%20not%20work%3C%2FSTRONG%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20when%20you%20test%20out%20and%20finish%20the%20script%2C%20simply%20schedule%20it%20using%20task%20scheduler.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHope%20this%20was%20helpful!%3C%2FP%3E%3CP%3ECheers!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hello everyone,

I need someone to help me to create an alert if my windows licence key is deactivated.

 

thank you

1 Reply
Highlighted

Hello @tonnybabs,

 

I've created a script which you can use, but you will probably have to edit it since I don't know what kind of licensing are you using. For example if you use Education License you will have to change the parameter in the script inside the 'where' condition. I will shortly explain how can you navigate through the PowerShell to get the information you need and send a notification via e-mail.

 

So before we begin I would recommend a short reading about windows license types:

https://secureinfra.blog/2019/01/13/understanding-volume-activation-services-part-1-kms-and-mak/

 

Basically what you need to do is to find out what you want to monitor with your script, for example in my script we will be monitoring Windows Operating System license, Enterprise Edition, Volume_KMSClient license family.

Firstly to get familiar with the output of the cmdlet I would recommend trying to execute this cmdlet:

Get-CimInstance -ClassName SoftwareLicensingProduct -ComputerName $env:COMPUTERNAME | where {$_.Description -eq "Windows(R) Operating System, VOLUME_KMSCLIENT channel"} | select description,licensefamily,licensestatus

Note: change the "Windows(R) Operating System, VOLUME_KMSCLIENT channel" with the licensing you use.

With that output you should get license status of the VOLUME_KMSCLIENT channel license family (or any other license family you use). With that cmdlet you will get more familiar of what you need and why is the script written the way it is.

 

$LicenseTest = Get-CimInstance -ClassName SoftwareLicensingProduct -ComputerName $env:COMPUTERNAME | where {$_.Description -eq "Windows(R) Operating System, VOLUME_KMSCLIENT channel" -and $_.LicenseFamily -eq "Enterprise"} | select -ExpandProperty licensestatus

if($LicenseTest -inotlike "1"){
Send-MailMessage -SmtpServer "YourSmtpServer" -From "AddressYouWantToSendItFrom" -To "AddressYouWantToNotify" -Body "$($env:COMPUTERNAME) | Not Licensed" -Subject "LicenseStatus"
}
else{
Send-MailMessage -SmtpServer "YourSmtpServer" -From "AddressYouWantToSendItFrom" -To "AddressYouWantToNotify" -Body "$($env:COMPUTERNAME) | Is Licensed" -Subject "LicenseStatus"
}

 

Also if you need it for more computers than one you can use foreach and load of list of computers in order to do this for every single one in the list, but if doing so I would recommend saving information in variable and than storing in .csv or .txt and send the file via mail (otherwise you will get spammed for every computer inspected with separated mail message).

Don't forget to read the script and replace with the data you need, copy/paste will not work.

 

So when you test out and finish the script, simply schedule it using task scheduler.

 

Hope this was helpful!

Cheers!