JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Untitled Page | JustPaste.app
4 months ago140 views
# Get logged-in user
$loggedInUser = (Get-CimInstance Win32_ComputerSystem).UserName
$username = $loggedInUser.Split("\")[-1]

# Output file
$OutputFile = "C:\Users\$username\Downloads\PC_Specs_Report.csv"

# Results array
$results = @()

# ------------------------------------------------------------
# Function: Decode Windows Product Key
# ------------------------------------------------------------
function Get-WindowsProductKey {

    try {
        $keyPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
        $digitalProductId = (Get-ItemProperty -Path $keyPath -Name DigitalProductId).DigitalProductId

        if (-not $digitalProductId) {
            return "Not Available"
        }

        $chars = "BCDFGHJKMPQRTVWXY2346789"
        $hexPid = $digitalProductId[52..67]
        $result = ""

        for ($i = 24; $i -ge 0; $i--) {
            $current = 0
            for ($j = 14; $j -ge 0; $j--) {
                $current = ($current * 256) -bxor $hexPid[$j]
                $hexPid[$j] = [math]::Floor($current / 24)
                $current = $current % 24
            }
            $result = $chars[$current] + $result
        }

        return $result.Insert(5,"-").Insert(11,"-").Insert(17,"-").Insert(23,"-")
    }
    catch {
        return "Not Available"
    }
}

# ------------------------------------------------------------
# Function: Get Primary User UPN (Corporate Email)
# ------------------------------------------------------------
function Get-PrimaryUserUPN {

    $path = "HKLM:\SOFTWARE\Microsoft\Enrollments"
    $enrollments = Get-ChildItem $path -ErrorAction SilentlyContinue

    foreach ($item in $enrollments) {
        $upn = (Get-ItemProperty -Path $item.PSPath -ErrorAction SilentlyContinue).UPN
        if ($upn) { return $upn }
    }

    return "Not Available"
}

# ------------------------------------------------------------
# Collect System Info
# ------------------------------------------------------------

# Hostname
$hostname = $env:COMPUTERNAME

# Computer system
$computer = Get-CimInstance Win32_ComputerSystem
$brand = $computer.Manufacturer
$model = $computer.Model

# Serial number
$serial = (Get-CimInstance Win32_BIOS).SerialNumber

# CPU
$cpu = (Get-CimInstance Win32_Processor).Name

# RAM (GB)
$ram = [math]::Round($computer.TotalPhysicalMemory / 1GB, 2)

# OS
$os = (Get-CimInstance Win32_OperatingSystem).Caption

# Storage (GB)
$disk = Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3"
$storageTotal = [math]::Round(($disk.Size | Measure-Object -Sum).Sum / 1GB, 2)

# Corporate Email
$corporateEmail = Get-PrimaryUserUPN

# Windows Product Key
$productKey = Get-WindowsProductKey

# ------------------------------------------------------------
# Add to results (ORDER MATTERS)
# ------------------------------------------------------------
$results += [PSCustomObject]@{
    CorporateEmail = $corporateEmail
    Hostname       = $hostname
    Brand          = $brand
    Model          = $model
    SerialNumber   = $serial
    CPU            = $cpu
    OS_Windows     = $os
    Storage_GB     = $storageTotal
    RAM_GB         = $ram
    ProductKey     = $productKey
}

# ------------------------------------------------------------
# Export CSV
# ------------------------------------------------------------
$results | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8

Write-Host "PC Spec report saved to: $OutputFile"

⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.

← Back to timeline