检测 win10 硬件部分的 小脚本
1.新建 win10.ps1 保留为 ansi运行powershell -ExecutionPolicy Bypass -File C:\Users\hp\Desktop\win10.ps12.代码# .SYNOPSIS 收集 Windows 10 系统的详细硬件信息并生成报告。 .DESCRIPTION 获取 CPU、内存、硬盘、电池、网卡等硬件的规格和状态信息。 结果以表格形式在控制台显示并可选择导出为 CSV 或文本文件。 # # --- 1. 基本信息 (OS, 主板, BIOS) --- Write-Host 系统与主板基本信息 -ForegroundColor Cyan Get-ComputerInfo -Property Cs*, Bios*, Os* | Select-Object CsManufacturer, CsModel, CsProcessors, CsTotalPhysicalMemory, BiosManufacturer, BiosVersion, BiosSMBIOSBIOSVersion, OsName, OsVersion, OsBuildNumber, WindowsInstallationType # --- 2. CPU 详细信息 --- Write-Host n CPU 信息 -ForegroundColor Cyan Get-CimInstance -ClassName Win32_Processor | Select-Object Name, Description, MaxClockSpeed, NumberOfCores, NumberOfLogicalProcessors, SocketDesignation, Manufacturer # --- 3. 物理内存 (品牌、频率、大小) --- Write-Host n 物理内存信息 -ForegroundColor Cyan # 注意内存品牌和频率可能因硬件和驱动支持情况而显示不全 Get-CimInstance -ClassName CIM_PhysicalMemory | Select-Object BankLabel, Capacity, Speed, Manufacturer, PartNumber, MemoryType # 内存总量 (GB) $totalMemoryGB [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 2) Write-Host 总物理内存: $totalMemoryGB GB -ForegroundColor Yellow # --- 4. 磁盘与固态硬盘 (大小、品牌、健康度) --- Write-Host n 磁盘与固态硬盘信息 -ForegroundColor Cyan # 物理磁盘信息 (包含型号、大小、健康状态) # Get-PhysicalDisk 在 PowerShell 5.1 (Win10) 中可用提供更详细的健康状态 Get-PhysicalDisk | Select-Object FriendlyName, Manufacturer, Model, Size, MediaType, HealthStatus, OperationalStatus # 逻辑分区空间使用情况 Write-Host n--- 逻辑分区使用情况 --- -ForegroundColor Yellow Get-CimInstance -ClassName Win32_LogicalDisk -Filter DriveType3 | ForEach-Object { $sizeGB [math]::Round($_.Size / 1GB, 2) $freeGB [math]::Round($_.FreeSpace / 1GB, 2) $freePercent [math]::Round(($_.FreeSpace / $_.Size) * 100, 2) [PSCustomObject]{ 盘符 $_.DeviceID 总大小_GB $sizeGB 可用空间_GB $freeGB 可用百分比 $freePercent% } } # --- 5. 电池信息 (笔记本电脑) --- Write-Host n 电池信息 -ForegroundColor Cyan $battery Get-CimInstance -ClassName Win32_Battery if ($battery) { $battery | Select-Object Name, Manufacturer, SerialNumber, Chemistry, DesignCapacity, FullChargeCapacity, BatteryStatus, EstimatedChargeRemaining, EstimatedRunTime } else { Write-Host 未检测到电池 (可能为台式机)。 -ForegroundColor Yellow } # --- 6. Wi-Fi 网卡信息 --- Write-Host n Wi-Fi 网卡信息 -ForegroundColor Cyan # 查找名称中包含 Wireless, Wi-Fi, WLAN, 802.11 的网络适配器 $wifiAdapters Get-CimInstance -ClassName Win32_NetworkAdapter | Where-Object { $_.Name -match Wireless|Wi-Fi|WLAN|802.11 -and $_.NetEnabled -eq $true } if ($wifiAdapters) { $wifiAdapters | ForEach-Object { $adapter $_ $ipConfig $adapter | Get-CimAssociatedInstance -ResultClassName Win32_NetworkAdapterConfiguration [PSCustomObject]{ 名称 $adapter.Name MAC地址 $adapter.MACAddress 速度_Mbps $adapter.Speed / 1000000 DHCP启用 $ipConfig.DHCPEnabled IP地址 $ipConfig.IPAddress -join , 子网掩码 $ipConfig.IPSubnet -join , 默认网关 $ipConfig.DefaultIPGateway -join , } } } else { Write-Host 未检测到已启用的 Wi-Fi 网卡。 -ForegroundColor Yellow } # --- 7. 总结与导出选项 --- Write-Host n 报告生成完成 -ForegroundColor Green $exportChoice Read-Host 是否导出报告为CSV文件? (Y/N) if ($exportChoice -eq Y -or $exportChoice -eq y) { $csvPath $env:USERPROFILE\Desktop\Hardware_Report_$(Get-Date -Format yyyyMMdd_HHmmss).csv # 为了便于导出将之前输出的信息重新组织为对象 (此处仅为示例实际可优化) Write-Host 正在导出... (请稍候此功能可进一步定制) -ForegroundColor Gray # 注此处简化处理实际生产中建议将所有信息整合到一个对象中再Export-Csv # 由于脚本中包含了多种格式的输出完整导出需要更复杂的逻辑。 # 你可以考虑使用 Get-CimInstance 的数据直接导出或者使用 Out-File 保存文本报告。 Write-Host 提示: 你可以使用 Get-CimInstance ... | Export-Csv 命令单独导出各部分数据。 -ForegroundColor Yellow }