Forum Discussion
Powershell alert for windos activation
Hello everyone,
I need someone to help me to create an alert if my windows licence key is deactivated.
thank you
- mbocakCopper Contributor
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!