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
3 months ago12 views
👨‍💻Programming
# Get logged-in username to save file in Downloads
$loggedInUser = (Get-CimInstance Win32_ComputerSystem).UserName
$username = $loggedInUser.Split("\")[-1]
$OutputFile = "C:\Users\$username\Downloads\PC_Specs_Report.csv"
 
# Create results array
$results = @()
 
# Function: Decode Windows Product Key
function Get-WindowsProductKey {
    $keyPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
    $digitalProductId = (Get-ItemProperty -Path $keyPath -Name DigitalProductId).DigitalProductId
 
    $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, "-")
}
 
# Function: Get Primary User UPN (from Intune/AAD)
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"
}
 
# Hostname
$hostname = $env:COMPUTERNAME
 
# Brand + Model
$computer = Get-CimInstance -ClassName Win32_ComputerSystem
$brand = $computer.Manufacturer
$model = $computer.Model
$brandModel = "$brand $model"
 
# Serial Number
$serial = (Get-CimInstance -ClassName Win32_BIOS).SerialNumber
 
# CPU
$cpu = (Get-CimInstance -ClassName Win32_Processor).Name
 
# RAM (GB)
$ram = [math]::Round($computer.TotalPhysicalMemory / 1GB, 2)
 
# OS Version
$os = (Get-CimInstance -ClassName Win32_OperatingSystem).Caption
 
# Storage (all drives combined)
$disk = Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3"
$storageTotal = [math]::Round(($disk.Size | Measure-Object -Sum).Sum / 1GB, 2)
 
# Product Key
$productKey = Get-WindowsProductKey
 
# Primary User UPN
$primaryUserUPN = Get-PrimaryUserUPN
 
# Add results in requested order
$results += [PSCustomObject]@{
    PrimaryUserUPN  = $primaryUserUPN
    Hostname        = $hostname
    BrandModel      = $brandModel
    SerialNumber    = $serial
    CPU             = $cpu
    OS              = $os
    StorageTotalGB  = $storageTotal
    RAM_GB          = $ram
    ProductKey      = $productKey
}
 
# Export to CSV
$results | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8
 
Write-Host "PC Spec report saved to: $OutputFile"
← Back to timeline