[英]How to force systeminfo output to english to parse it using 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
的輸出轉換為英語,以便對其進行解析?
我不知道如何為SysInfo設置語言,但是還有其他獲取相同信息的方法。 這將獲取CIM_ComputerSystem類報告的RAM。 該數字以字節為單位報告,因此除以1GB
得出的數字以GB為單位。 [ 咧嘴 ]
$Ram_GB = [math]::Round((Get-CimInstance -ClassName CIM_ComputerSystem).TotalPhysicalMemory / 1GB, 2)
$Ram_GB
在我的系統上輸出= 8
。
至少在相同的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
對我來說,替換 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 *
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.