如何使用Powershell强制将systeminfo输出转换为英语以进行解析?

时间:2019-05-01 21:31:02

标签: windows powershell

我有这个简单的代码字符串:

    $TotalMemory = (systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim()
    $TotalMemory = $TotalMemory -replace (",", "")
    $TotalMemory = $TotalMemory -replace ("MB", "")
    $TotalMemory | Set-Content ".\build\txt\ram.txt"

哪个收集RAM。工作良好。问题是我有一个使用俄语版本Windows的用户,该输出的语言为俄语。我有没有办法强制systeminfo的输出为英语,以便可以对其进行解析?

3 个答案:

答案 0 :(得分:1)

我不知道如何为SysInfo设置语言,但是还有其他方法可以获取相同的信息。这将获取CIM_ComputerSystem类报告的RAM。该数字以字节为单位报告,因此除以1GB得出的数字以GB为单位。 [咧嘴]

$Ram_GB = [math]::Round((Get-CimInstance -ClassName CIM_ComputerSystem).TotalPhysicalMemory / 1GB, 2)

$Ram_GB
我的系统上的

output = 8

答案 1 :(得分:1)

至少在相同的Windows版本中,systeminfo的标头计数应该相同。

因此,使用/FO csv/NH选项可以强制以csv格式输出无标题,并提供英文版本或带编号的列,即

Windows 10英文vs. Col#,德语

$SystemInfoHeadersEn = (
    "Host Name",#                 Col0  Hostname
    "OS Name",#                   Col1  Betriebssystemname
    "OS Version",#                Col2  Betriebssystemversion
    "OS Manufacturer",#           Col3  Betriebssystemhersteller
    "OS Configuration",#          Col4  Betriebssystemkonfiguration
    "OS Build Type",#             Col5  Betriebssystem-Buildtyp
    "Registered Owner",#          Col6  Registrierter Benutzer
    "Registered Organization",#   Col7  Registrierte Organisation
    "Product ID",#                Col8  Produkt-ID
    "Original Install Date",#     Col9  Ursprüngliches Installationsdatum
    "System Boot Time",#          Col10 Systemstartzeit
    "System Manufacturer",#       Col11 Systemhersteller
    "System Model",#              Col12 Systemmodell
    "System Type",#               Col13 Systemtyp
    "Processor(s)",#              Col14 Prozessor(en)
    "BIOS Version",#              Col15 BIOS-Version
    "Windows Directory",#         Col16 Windows-Verzeichnis
    "System Directory",#          Col17 System-Verzeichnis
    "Boot Device",#               Col18 Startgerät
    "System Locale",#             Col19 Systemgebietsschema
    "Input Locale",#              Col20 Eingabegebietsschema
    "Time Zone",#                 Col21 Zeitzone
    "Total Physical Memory",#     Col22 Gesamter physischer Speicher
    "Available Physical Memory",# Col23 Verfügbarer physischer Speicher
    "Virtual Memory: Max Size",#  Col24 Virtueller Arbeitsspeicher: Maximale Größe
    "Virtual Memory: Available",# Col25 Virtueller Arbeitsspeicher: Verfügbar
    "Virtual Memory: In Use",#    Col26 Virtueller Arbeitsspeicher: Zurzeit verwendet
    "Page File Location(s)",#     Col27 Auslagerungsdateipfad(e)
    "Domain",#                    Col28 Domäne
    "Logon Server",#              Col29 Anmeldeserver
    "Hotfix(s)",#                 Col30 Hotfix(es)
    "Network Card(s)",#           Col31 Netzwerkkarte(n)
    "Hyper-V Requirements"#       Col32 Anforderungen für Hyper-V
)

返回对象中的信息,但仍具有本地化/用户设置相关的值(小数点/逗号,日期格式)

> $SystemInfo = systeminfo.exe /FO csv /NH |ConvertFrom-Csv -Header $SystemInfoHeadersEn
> $systeminfo.'Total Physical Memory'
16.349 MB

> $SystemInfo = systeminfo.exe /FO csv /NH |ConvertFrom-Csv -Header (0..32|%{"Col$_"})
> $systeminfo.col22
16.349 MB

答案 2 :(得分:0)

对我来说,替代 systeminfo.exe(提供特定语言的输出)的解决方法是使用以下命令:

powershell -Command gcim CIM_ComputerSystem -Property *

提供以下内容:

AdminPasswordStatus         : 3
BootupState                 : Normal boot
ChassisBootupState          : 3
KeyboardPasswordStatus      : 3
PowerOnPasswordStatus       : 3
PowerSupplyState            : 3
PowerState                  : 0
FrontPanelResetStatus       : 3
ThermalState                : 3
Status                      : OK
Name                        : MYPC
PowerManagementCapabilities :
PowerManagementSupported    :
Caption                     : MYPCPW
Description                 : AT/AT COMPATIBLE
InstallDate                 :
CreationClassName           : Win32_ComputerSystem
NameFormat                  :
PrimaryOwnerContact         :
PrimaryOwnerName            : 
Roles                       : {LM_Workstation, LM_Server, NT}
InitialLoadInfo             :
LastLoadInfo                :
ResetCapability             : 1
AutomaticManagedPagefile    : True
AutomaticResetBootOption    : True
AutomaticResetCapability    : True
BootOptionOnLimit           :
BootOptionOnWatchDog        :
BootROMSupported            : True
BootStatus                  : {0, 0, 0, 0...}
ChassisSKUNumber            : Notebook
CurrentTimeZone             : 120
DaylightInEffect            : True
DNSHostName                 : MYPCPW
Domain                      : 
DomainRole                  : 1
EnableDaylightSavingsTime   : True
HypervisorPresent           : False
InfraredSupported           : False
Manufacturer                : Dell Inc.
Model                       : Precision 5530
NetworkServerModeEnabled    : True
NumberOfLogicalProcessors   : 12
NumberOfProcessors          : 1
OEMLogoBitmap               :
OEMStringArray              : {Dell System, 1[087D], 3[1.0], 12[www.dell.com]...}
PartOfDomain                : True
PauseAfterReset             : -1
PCSystemType                : 2
PCSystemTypeEx              : 2
ResetCount                  : -1
ResetLimit                  : -1
SupportContactDescription   :
SystemFamily                : Precision
SystemSKUNumber             : 087D
SystemStartupDelay          :
SystemStartupOptions        :
SystemStartupSetting        :
SystemType                  : x64-based PC
TotalPhysicalMemory         : 34079059968
UserName                    : uidg1234
WakeUpType                  : 6
Workgroup                   :
PSComputerName              :
CimClass                    : root/cimv2:Win32_ComputerSystem
CimInstanceProperties       : {Caption, Description, InstallDate, Name...}
CimSystemProperties         : Microsoft.Management.Infrastructure.CimSystemProperties

可以通过以下方式获取其他信息:

powershell -Command gcim CIM_Chip -Property *
powershell -Command gcim WIN32_Bios -Property *