Activating windows with powershell

Use PowerShell to Detect Activation Status

September 8th, 2014

Summary : Microsoft Scripting Guy, Ed Wilson, talks about using Windows PowerShell and WMI to display Windows activation status.

Hey, Scripting Guy! The previous network administrator at my company was not attentive to his work. I am not sure what he actually did for a living, but it certainly was not network administration. I think he was a professional Internet surfer. I suspect that many of our desktop operating systems are not activated properly. I want to produce a list of desktop systems, get the names and versions of the operating systems, and find out if the system is activated properly. Can I do this with Windows PowerShell?

Hello DB,

Microsoft Scripting Guy, Ed Wilson, is here. This morning I am still sore from my session with my new personal trainer. In fact, I am pretty sure that I am sore in muscles that I did not know that I had. I guess that means it is working…we will see. I am sipping a cup of Oolong tea this morning. Normally, I would have a black tea in the morning, but this morning, for some reason, I thought that Oolong would do the trick.

I brought back some very nice Oolong tea from Leipzi, Germany earlier this year, and I have been saving it for special occasions. I feel like this morning is a special occasion. With Oolong, especially a very nice Oolong, I do not add anything to the tea. No cinnamon stick, no lemon, no milk, and especially no sugar. Only tea. The Oolong has a very complex flavor, and I can close my eyes and taste the natural sweetness of the tea. There is no need to mess around with something that is already perfect.

Windows Management Instrumentation

There are numerous ways to access Windows Management Instrumentation (WMI) information by using Windows PowerShell. The best way is to use the CIM cmdlets. The CIM cmdlets shipped in Windows PowerShell 3.0 (with Windows 8 and Windows Server 2012), so they have been around for a while. The WMI team wrote a great article about CIM cmdlets on the Windows PowerShell Blog that you may want to read: Introduction to CIM Cmdlets.

To find information about current versions of Windows, I can use the SoftwareLicensingProduct WMI class. (For versions earlier than Windows 7, other WMI classes are required). The SoftwareLicensingProduct class is documented on MSDN, and it contains numerous methods that permit network administrators to completely manage Windows licensing. Two of the more useful methods (for me anyway) are the Active and the UninstallProductKey methods, both of which are pretty much self-explanatory as to what they do.

One reason for using the Get-CimInstance cmdlet is that I can create a CIM session pretty much automatically. This is because it relies on WINRM for remoting. It uses the same remoting technology as other Windows PowerShell remoting. This means that it is automatically activated and it simply works in Windows Server 2012 R2 and Windows Server 2012.

Читайте также:  Linux nano номер строки

For desktop operating systems, WinRM needs to be enabled, but that is easy enough to do via Group Policy (in larger environments) or via a logon script (for smaller environments). If you have been using Windows PowerShell for a while to manage your network, chances are good that you already have WinRM enabled.

I can easily query Active Directory Domain Services (AD DS) by using the Get-Computer cmdlet to retrieve a list of the computers I want to check. I can then feed that list to the New-CimSession cmdlet to create CIM sessions, and then I can use Get-CimInstance to retrieve my information.

That is how I might modify things to run against all of the computers on my network. For output, I would probably pipe the results to Export-CSV to create a nice file that I can open in Microsoft Excel for my documentation.

Getting licensing status

I am going to use the Get-CimInstance cmdlet to query the SoftwareLicensingProduct WMI class, and to find the ApplicationID for my version of Windows. This is sort of a magic number, and it takes a bit of searching on the Internet to find the information (it is not in the MSDN article for the WMI class).

I use the Get-CimInstance Windows PowerShell cmdlet, specify the WMI class, and pick up the ComputerName value from the environmental variable. I specify the ApplicationID property value for my filter, and I look for a LicenseStatus of 1 (this means it is activated, and this enumeration value does come from the MSDN article).

Then I select the name and description of the product, and I create a custom property that includes the name of the computer. For this example, I throw it to Format-List so I can see my results. Here is the script:

Get-CimInstance SoftwareLicensingProduct -ComputerName $env:computername `

-Filter «ApplicationID = ’55c92734-d682-4d71-983e-d6ec3f16059f'» |

where licensestatus -eq 1 |

Format-List name, description, computer

The use of the script and the associated output are shown in the following image:

DB, that is all there is to using Windows PowerShell to detect product activation status. WMI Week will continue tomorrow when I will talk about more cool stuff.

Activating windows with powershell

for Windows Powershell an own forum exists

Meinolf Weber

Microsoft MVP — Directory Services

Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

Twitter:

You can see how to get the License name / description from cscript ospp.vbs /dstatus to identify the License type. Once done, you can execute the required commands.

For scripting questions, you can ask them in the forums that Meinolf already mentioned.

This posting is provided AS IS with no warranties or guarantees , and confers no rights.

Читайте также:  Настройка перемещаемых профилей windows server 2019

Please note you can also use the cmd «slmgr» in Windows Powershell.

If you want to activate Windows via powershell script, please check the WMI class SoftwareLicensingService.

The script below can install the appropriate KMS client key for the detected OS:

If there is anything else regarding this issue, please feel free to post back.

TechNet Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

Hey there AnnaWY, with this awesome script you wrote, will it work remotely? Also, I’m not 100% sure how activating Enterprise editions works (never really. thought about it until one refused to update), my question is what do these keys do? Do they tell the computer, hey I’m this version of windows, now activate me if you have another license for me?

Anyway, thank you and I hope you don’t mind me waking up an old post! 🙂

Activating windows with powershell

for Windows Powershell an own forum exists

Meinolf Weber

Microsoft MVP — Directory Services

Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

Twitter:

You can see how to get the License name / description from cscript ospp.vbs /dstatus to identify the License type. Once done, you can execute the required commands.

For scripting questions, you can ask them in the forums that Meinolf already mentioned.

This posting is provided AS IS with no warranties or guarantees , and confers no rights.

Please note you can also use the cmd «slmgr» in Windows Powershell.

If you want to activate Windows via powershell script, please check the WMI class SoftwareLicensingService.

The script below can install the appropriate KMS client key for the detected OS:

If there is anything else regarding this issue, please feel free to post back.

TechNet Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

Hey there AnnaWY, with this awesome script you wrote, will it work remotely? Also, I’m not 100% sure how activating Enterprise editions works (never really. thought about it until one refused to update), my question is what do these keys do? Do they tell the computer, hey I’m this version of windows, now activate me if you have another license for me?

Anyway, thank you and I hope you don’t mind me waking up an old post! 🙂

How can I check if Windows is activated from the command prompt or powershell?

If I want to check whether Windows is activated, but I can’t be bothered to dive into the menu system or am on a version of Windows without Desktop Experience (such as Server Core), how can I check the activation status using only the command line?

Читайте также:  Soft для windows rus

4 Answers 4

A purely PowerShell solution would be:

This will give you an output like this:

if LicenseStatus is 1, it means that the system is permanently activated.

Good thing about this is, that you can easily check RemoteMachines, by specifying the -ComputerName Parameter.

Though I gotta say that slmgr /xpr is faster and also clearer.

On Windows 10 or Windows Server 2016/2019, to display the activation status using the command prompt (or powershell) open your preferred command line tool and enter the following command

a dialog is shown indicating the operating system’s activation status. If the operating system is not yet activated, the dialog will indicate it is in ‘Notification mode’

If Windows is succesfully activated, the dialog will indicate is is either ‘Permanently Activated’ as shown below, or if using a time-limited volume license activation the time the activation is due to expire will be shown.

On older versions of Windows (such as Windows 7) the message dialogs will be similar but may have slightly differing text.

This method could also be useful to check the activation status during the out-of-box experience (OOBE) wizard by using Shift + F10 to launch a command prompt, before completing the wizard.

Activating windows with powershell

for Windows Powershell an own forum exists

Meinolf Weber

Microsoft MVP — Directory Services

Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

Twitter:

You can see how to get the License name / description from cscript ospp.vbs /dstatus to identify the License type. Once done, you can execute the required commands.

For scripting questions, you can ask them in the forums that Meinolf already mentioned.

This posting is provided AS IS with no warranties or guarantees , and confers no rights.

Please note you can also use the cmd «slmgr» in Windows Powershell.

If you want to activate Windows via powershell script, please check the WMI class SoftwareLicensingService.

The script below can install the appropriate KMS client key for the detected OS:

If there is anything else regarding this issue, please feel free to post back.

TechNet Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com

Hey there AnnaWY, with this awesome script you wrote, will it work remotely? Also, I’m not 100% sure how activating Enterprise editions works (never really. thought about it until one refused to update), my question is what do these keys do? Do they tell the computer, hey I’m this version of windows, now activate me if you have another license for me?

Anyway, thank you and I hope you don’t mind me waking up an old post! 🙂

Оцените статью