编写Get-SystemInfo.bat,格式为ANSI
1@echo off
2
3chcp 936 > nul
4
5
6@echo off
7echo - **主机类型信息:**
8
9for /f "tokens=2 delims==" %%i in ('wmic computersystem get manufacturer /value') do set Manufacturer=%%i
10for /f "tokens=2 delims==" %%i in ('wmic computersystem get model /value') do set Model=%%i
11for /f "tokens=2 delims==" %%i in ('wmic computersystem get name /value') do set name=%%i
12
13for /f "tokens=2 delims==" %%i in ('wmic os get caption /value') do set OSName=%%i
14for /f "tokens=2 delims==" %%i in ('wmic os get version /value') do set OSVersion=%%i
15for /f "tokens=2 delims==" %%i in ('wmic os get osarchitecture /value') do set OSArchitecture=%%i
16
17
18for /f "tokens=2 delims==" %%i in ('wmic computersystem get SystemFamily /value') do set SystemFamily=%%i
19for /f "tokens=2 delims==" %%i in ('wmic computersystem get SystemSKUNumber /value') do set SystemSKUNumber=%%i
20
21
22
23for /f "tokens=2 delims==" %%i in ('wmic os get installdate /value') do set installdate=%%i
24for /f "tokens=2 delims==" %%i in ('wmic os get lastbootuptime /value') do set lastbootuptime=%%i
25
26
27
28for /f "tokens=2 delims==" %%i in ('wmic timezone get Caption /value') do set timezone=%%i
29
30
31
32if /i "%Manufacturer%"=="Microsoft Corporation" (
33 echo - 主机类型: 虚拟机
34) else if /i "%Manufacturer%"=="VMware, Inc." (
35 echo - 主机类型: 虚拟机
36) else if /i "%Manufacturer%"=="QEMU" (
37 echo - 主机类型: 虚拟机
38) else if /i "%Manufacturer%"=="Bochs" (
39 echo - 主机类型: 虚拟机
40) else if /i "%Manufacturer%"=="SANGFOR" (
41 echo - 主机类型: 虚拟机
42) else if /i "%Manufacturer%"=="OpenStack Foundation" (
43 echo - 主机类型: 虚拟机
44) else (
45 echo - 主机类型: 物理机
46)
47
48
49set "year=%installDate:~0,4%"
50set "month=%installDate:~4,2%"
51set "day=%installDate:~6,2%"
52set "hour=%installDate:~8,2%"
53set "minute=%installDate:~10,2%"
54set "second=%installDate:~12,2%"
55
56set "year1=%lastbootuptime:~0,4%"
57set "month1=%lastbootuptime:~4,2%"
58set "day1=%lastbootuptime:~6,2%"
59set "hour1=%lastbootuptime:~8,2%"
60set "minute1=%lastbootuptime:~10,2%"
61set "second1=%lastbootuptime:~12,2%"
62
63
64echo - 系统制造商: %Manufacturer%
65echo - 系统型号: %Model%
66echo - 主机名:%name%
67
68
69echo - 操作系统: %OSName%
70echo - 操作系统版本: %OSVersion%
71echo - 系统架构: %OSArchitecture%
72
73echo - 初始安装日期: %year%-%month%-%day% %hour%:%minute%:%second%
74echo - 系统启动时间: %year1%-%month1%-%day1% %hour1%:%minute1%:%second1%
75
76echo - SystemFamily: %SystemFamily%
77echo - SystemSKUNumber: %SystemSKUNumber%
78
79echo - 时区: %timezone%
80
81
82
83
84rem for /f "tokens=2 delims==" %%i in ('wmic computersystem get TotalPhysicalMemory /value') do set TotalPhysicalMemory=%%i
85
86setlocal enabledelayedexpansion
87
88for /f "tokens=*" %%a in ('powershell -command "(Get-CimInstance -ClassName Win32_ComputerSystem).TotalPhysicalMemory"') do (
89 set TotalPhysicalMemory=%%a
90)
91
92rem 去除空格
93set TotalPhysicalMemory=!TotalPhysicalMemory: =!
94
95rem 使用 PowerShell 转换为 GB
96if defined TotalPhysicalMemory (
97 for /f "tokens=*" %%i in ('powershell -command "[math]::Round([int64] !TotalPhysicalMemory! / 1073741824)"') do (
98 set TotalMemoryGB=%%i
99 )
100) else (
101 echo Error: TotalPhysicalMemory is not defined.
102)
103
104echo - 总物理内存大小(GB): %TotalMemoryGB% GB
105
106
107
108
109
110REM 获取CPU名称和核心数
111for /f "tokens=2 delims==" %%i in ('wmic cpu get name /value') do set CPUName=%%i
112for /f "tokens=2 delims==" %%i in ('wmic cpu get numberofcores /value') do set CPUNumCores=%%i
113for /f "tokens=2 delims==" %%i in ('wmic computersystem get numberoflogicalprocessors /value') do set CPULogicalProcessors=%%i
114echo - CPU型号: %CPUName%
115echo - 物理核心数: %CPUNumCores%
116echo - 逻辑处理器数 (线程数): %CPULogicalProcessors%
117
118
119
120echo.
121echo - **磁盘信息**:
122echo ```
123REM 获取磁盘信息
124wmic diskdrive get DeviceID,InterfaceType,model,mediatype,Description,Partitions,PNPDeviceID
125echo ```
126
127
128
129echo.
130echo - **文件系统信息**:
131echo ```
132rem wmic logicaldisk where "DriveType=3" get Caption,Description,VolumeName,FileSystem ,Size, FreeSpace
133powershell -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 }"
134
135
136echo ```
137
138echo.
139echo - **IP地址信息**:
140
141echo ```
142REM IP地址信息
143wmic nicconfig where "IPEnabled=true" get Description, IPAddress
144echo ```
145
146pause
结果
1- **主机类型信息:**
2 - 主机类型: 虚拟机
3 - 系统制造商: VMware, Inc.
4 - 系统型号: VMware Virtual Platform
5 - 主机名:HF-SERVER79
6 - 操作系统: Microsoft Windows Server 2012 R2 Standard
7 - 操作系统版本: 6.3.9600
8 - 系统架构: 64 位
9 - 初始安装日期: 2017-03-07 07:48:41
10 - 系统启动时间: 2023-09-21 16:59:17
11 - SystemFamily:
12 - SystemSKUNumber:
13 - 时区: (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi
14 - 总物理内存大小(GB): 32 GB
15 - CPU型号: Intel(R) Xeon(R) CPU E5-2640 v4 @ 2.40GHz
16 - 物理核心数: 4
17 - 逻辑处理器数 (线程数): 8
18
19- **磁盘信息**:
20```
21Description DeviceID InterfaceType MediaType Model Partitions PNPDeviceID
22磁盘驱动器 \\.\PHYSICALDRIVE1 SCSI Fixed hard disk media VMware Virtual disk SCSI Disk Device 1 SCSI\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\5&22BE343F&0&000100
23磁盘驱动器 \\.\PHYSICALDRIVE0 SCSI Fixed hard disk media VMware Virtual disk SCSI Disk Device 2 SCSI\DISK&VEN_VMWARE&PROD_VIRTUAL_DISK\5&22BE343F&0&000000
24
25```
26
27- **文件系统信息**:
28```
29Drive | Volume Name | File System| Total Size (GB) | Free Space (GB)
30---------- | --------------- | ---------- | --------------- | ---------------
31C: | | NTFS | 99.66 | 35.39
32D: | 新建卷 | NTFS | 299.97 | 134.35
33```
34
35- **IP地址信息**:
36```
37Description IPAddress
38Intel(R) 82574L 千兆网络连接 {"192.17.1.79", "fe80::8010:4e6a:d9d7:f13a"}
39
40```
解析后的结果: