#Requires -RunAsAdministrator try { $session = New-CimSession $serial = (Get-CimInstance -CimSession $session -Class Win32_BIOS).SerialNumber $devDetail = (Get-CimInstance -CimSession $session -Namespace root/cimv2/mdm/dmmap ` -Class MDM_DevDetail_Ext01 -Filter "InstanceID='Ext' AND ParentID='./DevDetail'") if (-not $devDetail) { $err = [Management.Automation.ErrorRecord]::new( "Unable to retrieve device hardware details", "DevDetailNullError", [Management.Automation.ErrorCategory]::DeviceError, $null ) throw $err } if ([string]::IsNullOrEmpty($devDetail.DeviceHardwareData)) { $err = [Management.Automation.ErrorRecord]::new( "Unable to retrieve device hardware hash", "DevHardwareDataNullOrEmptyError", [Management.Automation.ErrorCategory]::DeviceError, $null ) throw $err } $c = New-Object PSObject -Property @{ "Device Serial Number" = $serial "Windows Product ID" = "" "Hardware Hash" = $devDetail.DeviceHardwareData "Group Tag" = "CHANGEME" } $outputPath = "C:\tmp" if (-not (Test-Path -Path $outputPath)) { New-Item -ItemType Directory -Path $outputPath } Push-Location $outputPath $output = $c | Select-Object "Device Serial Number", "Windows Product ID", "Hardware Hash", ` "Group Tag" | ConvertTo-CSV -NoTypeInformation | ForEach-Object { $_ -replace '"', '' } $output | Out-File -FilePath "$($serial).csv" Write-Output "Hardware ID saved as $($serial).csv" Invoke-Item . Pop-Location } catch { $PSCmdlet.ThrowTerminatingError($_) } finally { Remove-CimSession $session }