Recently, I got a requirement from a client to get the Windows product keys using PowerShell from various Windows OS. In this tutorial, I will explain how to retrieve your Windows Product Key using PowerShell.
If you ever need to reinstall Windows or transfer your license to a new computer, having your product key handy can save you a lot of time and hassle. In this tutorial, I will explain how you can easily find your Windows product key using PowerShell.
Note: Ensure you have access to a Windows computer and administrator privileges to run PowerShell commands.
Retrieve Your Windows Product Key Using PowerShell
There are a few different ways to view your Windows 10 or 11 product key, but using PowerShell is one of the quickest and most reliable methods. I recently had to retrieve my product key when setting up a new PC for a client in New York, and PowerShell made the process a breeze.
Your Windows Product Key is essential for activating your operating system. If you lose it, you may face difficulties during reinstallation or when upgrading your system. Here, I will show you how to use PowerShell, a powerful command-line tool, to retrieve your product key easily.
Check out How to Enable WinRM (Windows Remote Management) Using PowerShell?
Method 1: Using PowerShell to Find the Product Key from the Registry
PowerShell can be used to access the Windows registry, where the product key is stored. Follow these steps:
- Open the Windows PowerShell as an administrator (Press
Win + Xand select “Windows PowerShell (Admin)” from the menu). - Then, run the below PowerShell cmdlet to get the Windows product key.
(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey- This will display the product key, as shown in the screenshot below.

Read Get Windows Services Using PowerShell
Method 2: Using a PowerShell Script
For those who prefer using scripts, you can create a PowerShell script to automate the process:
- Open Notepad or any text editor and paste the following script:
function Get-WindowsKey {
$key = (Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
return $key
}
$ProductKey = Get-WindowsKey
Write-Output "Your Windows Product Key is: $ProductKey"- Save the file with a
.ps1extension, for example,GetWindowsKey.ps1. - Then, run the PowerShell script for this follow the below steps:
- Open PowerShell as an Administrator.
- Navigate to the directory where you saved the script using the
cdcommand. - Execute the script by typing
.\GetWindowsKey.ps1and pressingEnter.
- The script will output your Windows product key in the PowerShell window. You can see the output in the screenshot below:

Read How to Get Windows Activation Status Using PowerShell?
Troubleshooting Common Issues
Now, let me explain some troubleshooting steps to you. These are very common, and you might get these errors while executing the steps above.
No Product Key Found
If the PowerShell commands do not return a product key, it could be due to several reasons:
- OEM Key Missing:
If you purchased a pre-built PC, the product key might be embedded in the BIOS/UEFI firmware. Use the following command to check:
powershell (Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey- Incorrect Command:
- Ensure that you have typed the command correctly. Even a small typo can cause the command to fail.
- Administrator Privileges:
- Make sure you are running PowerShell as an administrator. Without the necessary permissions, PowerShell cannot access the registry or WMI.
Conclusion
In this tutorial, I explained two different methods to retrieve Windows product keys using PowerShell.
You may also like:
- Get the Windows Version Using PowerShell
- How to Set Default Browser Using PowerShell?
- Find Installed Software Using PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.