Use this powershell script and deploy it using intune.
Function Get-SystemSpecs {
$processorSpecs = Get-CimInstance win32_processor
$processorName = $processorSpecs.Name
$processorSpeed = [string]([math]::round(($processorSpecs.CurrentClockSpeed /1000),2)) + 'ghz'
$processorCores = $processorSpecs.NumberOfCores
$processorThreads = $processorSpecs.ThreadCount
$ramTotal = "{0:N2}" -f (((Get-CimInstance CIM_PhysicalMemory | select -ExpandProperty Capacity) | measure -Sum).sum /1gb )
Function Get-RAMDetails {
$RAM = Get-CimInstance CIM_PhysicalMemory | where {$_.CreationClassName -like "Win32_PhysicalMemory"}
$RAM = $RAM | ForEach{ $_.DeviceLocator + ": " + ($_.Capacity / 1GB) + "GB, " + ($(if ($RAM.SMBIOSMemoryType -eq "24"){"DDR3-"} ElseIf ($RAM.SMBIOSMemoryType -eq "26"){"DDR4-"} ElseIf ($RAM.SMBIOSMemoryType -eq "34"){"DDR5-"} Else {"Unknown-"})) + $_.ConfiguredClockSpeed + "MHz" + " (" + $_.Manufacturer +")"}
If ($RAM.Count -gt 1) { $RAM = [String]::Join(", ",$RAM)}
Return $RAM
}
Function Get-HDDDetails {
$HDD = Get-CimInstance Win32_DiskDrive | where {$_.MediaType -like "Fixed*"}
$HDD = $HDD | ForEach{ $_.caption + ", Capacity: " + [math]::round(($_.Size / 1GB),'2') + "GB" }
If ($HDD.Count -gt 1) { $HDD = [String]::Join(", ",$HDD)}
Return $HDD
}
$Specs = @{
'ComputerName' = $env:ComputerName
'Processor' = $processorName
'Cores' = $processorCores
'ThreadCount' = $processorThreads
'ProcessorClockSpeed' = $processorSpeed
'Physical Memory Size' = $ramTotal + ' GB'
'Memory chip(s)' = Get-RAMDetails
'System Type' = Get-CimInstance win32_operatingsystem | select -ExpandProperty OSArchitecture
'Hard Drive(s)' = Get-HDDDetails
'Serial' = Get-CimInstance win32_bios | select -expandproperty serialnumber
'OS' = Get-CimInstance win32_operatingsystem | select -expandproperty caption
}
Return $Specs
}
Get-SystemSpecs | ConvertTo-Json -Compress
Then use this graph api script to pull the hardware details returned by the powershell script.
# Set the required variables
$tenantId = "<Your Tenant ID>"
$clientId = "<Your Client ID>"
$clientSecret = "<Your Client Secret>"
$ScriptGUID = "<Your Script GUID>"
$URL = "https://graph.microsoft.com/beta/deviceManagement/deviceManagementScripts/$ScriptGUID/deviceRunStates?`$expand=managedDevice"
# Authenticate and get an access token
$body = @{
Grant_Type = "client_credentials"
Scope = "https://graph.microsoft.com/.default"
Client_Id = $clientId
Client_Secret = $clientSecret
}
$tokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -Method Post -ContentType "application/x-www-form-urlencoded" -Body $body
$accessToken = $tokenResponse.access_token
# Retrieve the data from the specified endpoint
$headers = @{
Authorization = "Bearer $accessToken"
'Content-Type' = "application/json"
}
$response = Invoke-RestMethod -Uri $URL -Headers $headers -Method Get
$deviceRunStates = $response.value
# Prepare an array to hold the final data
$finalData = @()
foreach ($deviceRunState in $deviceRunStates) {
$resultMessage = $deviceRunState.resultMessage | convertFrom-Json
$finalData += [PSCustomObject]@{
ComputerName = $resultMessage.ComputerName
Processor = $resultMessage.Processor
Cores = $resultMessage.Cores
ThreadCount = $resultMessage.ThreadCount
ProcessorClockSpeed = $resultMessage.ProcessorClockSpeed
RamTotal = $resultMessage.'Physical Memory Size'
RamDetails = $resultMessage.'Memory chip(s)'
SystemType = $resultMessage.'System Type'
HardDriveDetails = $resultMessage.'Hard Drive(s)'
OS = $resultMessage.OS
Serial = $resultMessage.Serial
RunState = $deviceRunState.runState
ErrorCode = $deviceRunState.errorCode
ErrorDescription = $deviceRunState.errorDescription
LastStateUpdateDateTime = $deviceRunState.lastStateUpdateDateTime
}
}
# Export the data to a CSV file
$finalData | Export-Csv -Path "C:\temp\IntuneDeviceRunStates.csv" -NoTypeInformation