|
| 1 | +$ErrorActionPreference = 'SilentlyContinue' |
| 2 | + |
| 3 | +try { |
| 4 | + # Get system information |
| 5 | + $allCpus = Get-CimInstance Win32_Processor |
| 6 | + $cpu = $allCpus | Select-Object -First 1 |
| 7 | + $cs = Get-CimInstance Win32_ComputerSystem |
| 8 | + $os = Get-CimInstance Win32_OperatingSystem |
| 9 | + $mem = Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum |
| 10 | + $disk = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Free -ne $null} | Measure-Object -Property Used,Free -Sum |
| 11 | + |
| 12 | + # Calculate CPU topology |
| 13 | + $socketCount = $allCpus.Count |
| 14 | + $coresPerSocket = $cpu.NumberOfCores |
| 15 | + $totalCores = ($allCpus | Measure-Object -Property NumberOfCores -Sum).Sum |
| 16 | + $logicalProcessors = $cs.NumberOfLogicalProcessors |
| 17 | + $threadsPerCore = if ($totalCores -gt 0) { [math]::Round($logicalProcessors / $totalCores, 0) } else { 1 } |
| 18 | + |
| 19 | + # Output lscpu-like information |
| 20 | + $output = @() |
| 21 | + $output += "Architecture: $($cpu.Architecture)" |
| 22 | + $output += "CPU op-mode(s): $(if($cpu.AddressWidth -eq 64){'32-bit, 64-bit'}else{'32-bit'})" |
| 23 | + $output += "Byte Order: Little Endian" |
| 24 | + $output += "CPU(s): $logicalProcessors" |
| 25 | + $output += "On-line CPU(s) list: 0-$(($logicalProcessors)-1)" |
| 26 | + $output += "Thread(s) per core: $threadsPerCore" |
| 27 | + $output += "Core(s) per socket: $coresPerSocket" |
| 28 | + $output += "Socket(s): $socketCount" |
| 29 | + $output += "Vendor ID: $($cpu.Manufacturer)" |
| 30 | + $output += "CPU family: $($cpu.Family)" |
| 31 | + $output += "Model: $($cpu.Model)" |
| 32 | + $output += "Model name: $($cpu.Name)" |
| 33 | + $output += "Stepping: $($cpu.Stepping)" |
| 34 | + $output += "CPU MHz: $($cpu.CurrentClockSpeed)" |
| 35 | + $output += "CPU max MHz: $($cpu.MaxClockSpeed)" |
| 36 | + $output += "Virtualization: $(if($cpu.VirtualizationFirmwareEnabled){'Enabled'}else{'Disabled'})" |
| 37 | + if ($cpu.L1CacheSize) { $output += "L1d cache: $($cpu.L1CacheSize) KB" } |
| 38 | + if ($cpu.L2CacheSize) { $output += "L2 cache: $($cpu.L2CacheSize) KB" } |
| 39 | + if ($cpu.L3CacheSize) { $output += "L3 cache: $($cpu.L3CacheSize) KB" } |
| 40 | + $output += "Flags: $($cpu.Description)" |
| 41 | + |
| 42 | + # Write to tmp-lscpu.out |
| 43 | + $output | Out-File -FilePath "tmp-lscpu.out" -Encoding ASCII |
| 44 | + |
| 45 | + # Export CPU details to CSV with UTF-8 encoding (with BOM for Python compatibility) |
| 46 | + $cpu | Export-Csv -Path "tmp-wmic-cpu.csv" -NoTypeInformation -Encoding UTF8 |
| 47 | + |
| 48 | + # Generate systeminfo CSV for compatibility |
| 49 | + $systemInfo = [PSCustomObject]@{ |
| 50 | + 'Host Name' = $env:COMPUTERNAME |
| 51 | + 'OS Name' = $os.Caption |
| 52 | + 'OS Version' = $os.Version |
| 53 | + 'OS Manufacturer' = $os.Manufacturer |
| 54 | + 'OS Configuration' = $os.OSType |
| 55 | + 'OS Build Type' = $os.BuildType |
| 56 | + 'System Manufacturer' = $cs.Manufacturer |
| 57 | + 'System Model' = $cs.Model |
| 58 | + 'System Type' = $cs.SystemType |
| 59 | + 'Processor(s)' = "$($allCpus.Count) Processor(s) Installed." |
| 60 | + 'Total Physical Memory' = "$memGB GB" |
| 61 | + 'Domain' = $cs.Domain |
| 62 | + } |
| 63 | + $systemInfo | Export-Csv -Path "tmp-systeminfo.csv" -NoTypeInformation -Encoding UTF8 |
| 64 | + |
| 65 | + # Calculate memory and disk capacity |
| 66 | + $memGB = [math]::Round($mem.Sum / 1GB, 2) |
| 67 | + $diskUsedGB = [math]::Round(($disk | Where-Object {$_.Property -eq 'Used'}).Sum / 1GB, 2) |
| 68 | + $diskFreeGB = [math]::Round(($disk | Where-Object {$_.Property -eq 'Free'}).Sum / 1GB, 2) |
| 69 | + $diskTotalGB = $diskUsedGB + $diskFreeGB |
| 70 | + |
| 71 | + # Write environment variables |
| 72 | + $envOutput = @() |
| 73 | + $envOutput += "MLC_HOST_MEMORY_CAPACITY=${memGB}G" |
| 74 | + $envOutput += "MLC_HOST_DISK_CAPACITY=${diskTotalGB}G" |
| 75 | + $envOutput += "MLC_HOST_CPU_MICROCODE=$($cpu.Revision)" |
| 76 | + $envOutput += "MLC_HOST_CPU_WRITE_PROTECT_SUPPORT=Not Available on Windows" |
| 77 | + $envOutput += "MLC_HOST_CPU_FPU_SUPPORT=$(if($cpu.ProcessorType -ge 3){'yes'}else{'Not Found'})" |
| 78 | + $envOutput += "MLC_HOST_CPU_FPU_EXCEPTION_SUPPORT=Not Available on Windows" |
| 79 | + $envOutput += "MLC_HOST_CPU_BUGS=Not Available on Windows" |
| 80 | + $envOutput += "MLC_HOST_CPU_TLB_SIZE=Not Available on Windows" |
| 81 | + $envOutput += "MLC_HOST_CPU_CFLUSH_SIZE=Not Available on Windows" |
| 82 | + $envOutput += "MLC_HOST_CACHE_ALIGNMENT_SIZE=$($cpu.DataWidth) bits" |
| 83 | + $envOutput += "MLC_HOST_POWER_MANAGEMENT=$(if($cpu.PowerManagementSupported){'Supported'}else{'Not Supported'})" |
| 84 | + |
| 85 | + $envOutput | Out-File -FilePath "tmp-run-env.out" -Encoding ASCII |
| 86 | + |
| 87 | + exit 0 |
| 88 | +} catch { |
| 89 | + Write-Error $_.Exception.Message |
| 90 | + exit 1 |
| 91 | +} |
0 commit comments