原 Windows环境下,bat脚本一键获取操作系统主机配置信息
编写Get-SystemInfo.bat,格式为ANSI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | @echo off chcp 936 > nul @echo off echo - **主机类型信息:** for /f "tokens=2 delims==" %%i in ('wmic computersystem get manufacturer /value') do set Manufacturer=%%i for /f "tokens=2 delims==" %%i in ('wmic computersystem get model /value') do set Model=%%i for /f "tokens=2 delims==" %%i in ('wmic computersystem get name /value') do set name=%%i for /f "tokens=2 delims==" %%i in ('wmic os get caption /value') do set OSName=%%i for /f "tokens=2 delims==" %%i in ('wmic os get version /value') do set OSVersion=%%i for /f "tokens=2 delims==" %%i in ('wmic os get osarchitecture /value') do set OSArchitecture=%%i for /f "tokens=2 delims==" %%i in ('wmic computersystem get SystemFamily /value') do set SystemFamily=%%i for /f "tokens=2 delims==" %%i in ('wmic computersystem get SystemSKUNumber /value') do set SystemSKUNumber=%%i for /f "tokens=2 delims==" %%i in ('wmic os get installdate /value') do set installdate=%%i for /f "tokens=2 delims==" %%i in ('wmic os get lastbootuptime /value') do set lastbootuptime=%%i for /f "tokens=2 delims==" %%i in ('wmic timezone get Caption /value') do set timezone=%%i if /i "%Manufacturer%"=="Microsoft Corporation" ( echo - 主机类型: 虚拟机 ) else if /i "%Manufacturer%"=="VMware, Inc." ( echo - 主机类型: 虚拟机 ) else if /i "%Manufacturer%"=="QEMU" ( echo - 主机类型: 虚拟机 ) else if /i "%Manufacturer%"=="Bochs" ( echo - 主机类型: 虚拟机 ) else if /i "%Manufacturer%"=="SANGFOR" ( echo - 主机类型: 虚拟机 ) else if /i "%Manufacturer%"=="OpenStack Foundation" ( echo - 主机类型: 虚拟机 ) else ( echo - 主机类型: 物理机 ) set "year=%installDate:~0,4%" set "month=%installDate:~4,2%" set "day=%installDate:~6,2%" set "hour=%installDate:~8,2%" set "minute=%installDate:~10,2%" set "second=%installDate:~12,2%" set "year1=%lastbootuptime:~0,4%" set "month1=%lastbootuptime:~4,2%" set "day1=%lastbootuptime:~6,2%" set "hour1=%lastbootuptime:~8,2%" set "minute1=%lastbootuptime:~10,2%" set "second1=%lastbootuptime:~12,2%" echo - 系统制造商: %Manufacturer% echo - 系统型号: %Model% echo - 主机名:%name% echo - 操作系统: %OSName% echo - 操作系统版本: %OSVersion% echo - 系统架构: %OSArchitecture% echo - 初始安装日期: %year%-%month%-%day% %hour%:%minute%:%second% echo - 系统启动时间: %year1%-%month1%-%day1% %hour1%:%minute1%:%second1% echo - SystemFamily: %SystemFamily% echo - SystemSKUNumber: %SystemSKUNumber% echo - 时区: %timezone% rem for /f "tokens=2 delims==" %%i in ('wmic computersystem get TotalPhysicalMemory /value') do set TotalPhysicalMemory=%%i setlocal enabledelayedexpansion for /f "tokens=*" %%a in ('powershell -command "(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory"') do ( set TotalPhysicalMemory=%%a ) rem 去除空格 set TotalPhysicalMemory=!TotalPhysicalMemory: =! rem 使用 PowerShell 转换为 GB if defined TotalPhysicalMemory ( for /f "tokens=*" %%i in ('powershell -command "[math]::Round([int64] !TotalPhysicalMemory! / 1073741824)"') do ( set TotalMemoryGB=%%i ) ) else ( echo Error: TotalPhysicalMemory is not defined. ) echo - 总物理内存大小(GB): %TotalMemoryGB% GB REM 获取CPU名称和核心数 for /f "tokens=2 delims==" %%i in ('wmic cpu get name /value') do set CPUName=%%i for /f "tokens=2 delims==" %%i in ('wmic cpu get numberofcores /value') do set CPUNumCores=%%i for /f "tokens=2 delims==" %%i in ('wmic computersystem get numberoflogicalprocessors /value') do set CPULogicalProcessors=%%i echo - CPU型号: %CPUName% echo - 物理核心数: %CPUNumCores% echo - 逻辑处理器数 (线程数): %CPULogicalProcessors% echo. echo - **磁盘信息**: echo ``` REM 获取磁盘信息 wmic diskdrive get DeviceID,InterfaceType,model,mediatype,Description,Partitions,PNPDeviceID echo ``` echo. echo - **文件系统信息**: echo ``` rem wmic logicaldisk where "DriveType=3" get Caption,Description,VolumeName,FileSystem ,Size, FreeSpace powershell -command "$drives = Get-WmiObject -Class Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 }; '{0,-10} | {1,-15} | {2,-10} | {3,15} | {4,15}' -f 'Drive', 'Volume Name', 'File System', 'Total Size (GB)', 'Free Space (GB)'; '{0,-10} | {1,-15} | {2,-10} | {3,15} | {4,15}' -f '----------', '---------------', '----------', '---------------', '---------------'; $drives | ForEach-Object { $drive = $_.DeviceID; $volumeName = $_.VolumeName; $fileSystem = $_.FileSystem; $totalSize = [math]::Round($_.Size / 1GB, 2); $freeSpace = [math]::Round($_.FreeSpace / 1GB, 2); '{0,-10} | {1,-15} | {2,-10} | {3,15:N2} | {4,15:N2}' -f $drive, $volumeName, $fileSystem, $totalSize, $freeSpace }" echo ``` echo. echo - **IP地址信息**: echo ``` REM IP地址信息 wmic nicconfig where "IPEnabled=true" get Description, IPAddress echo ``` pause |