Getting the Product ID

I’m trying to figure out how to get the information from all of our machines using Powershell to import into AutoPilot.

I think I’ve got most of it working, but the commands I have found using Powershell do not work as expected when pulling the Product ID. We have a mix of the different types of keys, so I’m wondering if that is it. If I use the command (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey I get the following:

Get-WmiObject : A positional parameter cannot be found that accepts argument ‘*’.

I can use the command line and pull that info, but how do I get it into the variable?

Get system information

$serialNumber = Get-WmiObject win32_bios | Select-Object -ExpandProperty SerialNumber
$productId = wmic path softwarelicensingservice get OA3xOriginalProductKey
$hardwareHash = Get-WmiObject -Class “Win32_ComputerSystemProduct” | Select-Object -ExpandProperty UUID
$model = Get-WmiObject -Class “Win32_ComputerSystem” | Select-Object -ExpandProperty Model

Define output file path

$outputFile = “\MCITS\ITS\HardHash\output.csv”

Create output file if it doesn’t exist

if (-not (Test-Path $outputFile)) {
New-Item -Path $outputFile -ItemType File

Append system information to output file

$data = [pscustomobject]@{
SerialNumber = $serialNumber
ProductId = $productId
HardwareHash = $hardwareHash
Model = $model
$data | Export-Csv -Path $outputFile -Append -NoTypeInformation

Welcome to the forum. :wave:t4:

Before we proceed … please go back, edit your question and fix the formatting of your code.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

Start with this command, to check result that you have.

Get-WmiObject -query 'select * from SoftwareLicensingService'

Property OA3xOriginalProductKey should be there.