OSDeploy / OSD

OSD Shared Functions
MIT License
132 stars 54 forks source link

Get Windows product by emeded OEM Key #84

Closed Abe-Telo closed 6 months ago

Abe-Telo commented 8 months ago

Describe the solution you'd like It would be cool to get the Windows type based on the Embedded Windows Key from the bios. Such as Windows 10 Home, Pro, Enterprise, etc. It would be even cooler If the tool could tell us if the Product key can be used for Win 10 and Win 11.

I was thinking of even a step forward and filtering the Windows selection from the OSDCloudGUI Menu based on the product key.

What this resolves Sometimes I have Windows 10 Pro, But I install Home. Sometimes I want to downgrade from Windows 11 to 10, And not sure if the product key allows it.

Having something like this implemented can save alot of time.

AkosBakos commented 8 months ago

I think it could be hard to automate, because the use case is for every user/customer different. --> if you need this activation, you can simply extend your code with these lines: https://github.com/AkosBakos/OSDCloud/blob/main/Install-EmbeddedProductKey.ps1

Abe-Telo commented 8 months ago

Thank you, i will test it, I assume we use it by adding a line

Invoke-Expression (Invoke-WebRequest -Uri "https://github.com/AkosBakos/OSDCloud/blob/main/Install-EmbeddedProductKey.ps1" -UseBasicParsing).Content

Correct?

AkosBakos commented 8 months ago

Or simply like that: Start-Process PowerShell -ArgumentList "-NoL -C Invoke-WebPSScript "https://github.com/AkosBakos/OSDCloud/blob/main/Install-EmbeddedProductKey.ps1" -Wait

Abe-Telo commented 8 months ago

Or simply like that: Start-Process PowerShell -ArgumentList "-NoL -C Invoke-WebPSScript "https://github.com/AkosBakos/OSDCloud/blob/main/Install-EmbeddedProductKey.ps1" -Wait

I can confirm it works in windows, but doesn't seem to work in WinPE. Normal behavior?

In windows I ran the 1.cmd in system32 from his script and it worked.

AkosBakos commented 8 months ago

Check the log file: $env:ProgramData\Microsoft\IntuneManagementExtension\Logs\OSD\Install-EmbeddedProductKey.log --> if the device has a HW license, it doesn't matter in which phase is getting executed.

Abe-Telo commented 8 months ago

@AkosBakos, I believe in WinPE we will get Invalid class "SoftwareLicensingService" Since i am using PowerShell and not CMD to run my script, I used these 2 lines of code.

$EmbeddedProductKey= "https://raw.githubusercontent.com/AkosBakos/OSDCloud/main/Install-EmbeddedProductKey.ps1"
Invoke-Expression (Invoke-WebRequest -Uri $EmbeddedProductKey-UseBasicParsing).Content

Here is the log file you requested. Tested on 2 Surface Books. Here is how i have it implemented online on line 60. https://github.com/Abe-Telo/ODSCloud-Missing-Microsoft-Drivers/blob/main/online.ps1

**********************
Transcript started, output file is X:\ProgramData\Microsoft\IntuneManagementExtension\Logs\OSD\2023-11-15-140536-Install-EmbeddedProductKey.log
Get embedded product key
Get-WmiObject : Invalid class "SoftwareLicensingService"
At line:5 char:9
+ $Key = (Get-WmiObject SoftwareLicensingService).OA3xOriginalProductKe ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand
Get-WmiObject : Invalid class "SoftwareLicensingService"
At line:5 char:9
+ $Key = (Get-WmiObject SoftwareLicensingService).OA3xOriginalProductKe ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

No embedded product key found.
**********************
gwblok commented 6 months ago

The OSD Module has functions for getting the embedded code, and for applying it to the OS. https://github.com/OSDeploy/OSD/blob/master/Public/OSDCloudTS/Set-WindowsOEMActivation.ps1

image

It has worked pretty well for me in my process, applying the Key from older devices and activating Windows 11, but sadly I've had poor luck lately: https://www.zdnet.com/article/can-you-still-get-a-windows-10-upgrade-for-free/

Still works find on newer hardware.

If you OEMActivation = $true in your OSDCloud variables, it should automatically try to get the key and apply it for you. See my OSDCloud script example: https://github.com/gwblok/garytown/blob/master/Dev/CloudScripts/win11.ps1

gwblok commented 6 months ago

Describe the solution you'd like It would be cool to get the Windows type based on the Embedded Windows Key from the bios. Such as Windows 10 Home, Pro, Enterprise, etc. It would be even cooler If the tool could tell us if the Product key can be used for Win 10 and Win 11.

I was thinking of even a step forward and filtering the Windows selection from the OSDCloudGUI Menu based on the product key.

What this resolves Sometimes I have Windows 10 Pro, But I install Home. Sometimes I want to downgrade from Windows 11 to 10, And not sure if the product key allows it.

Having something like this implemented can save alot of time.

I just looked back at the original request, which is different then what I was thinking. While it's a cool idea, I don't know of a way to do a look up on the OEM code and get the OS it is for. If you know of a way to do this, let me know and I can see if I can work it into the process.

Today, the best way to do this would be to write a custom script to kick off OSDCloud, have it check for a list of models you image that are known to be Pro, and then have do something like if (Activation -eq "Pro"){$Activation = "Pro"} Else {$Activation = "Home"} Then feed that into your Start-OSDCloud Command line.

Considering this Issue closed unless someone provides a method to do a lookup on the MS Activation Code in the Firmware.