我有一个简单的代码字符串:
$TotalMemory = (systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim()
$TotalMemory = $TotalMemory -replace (",", "")
$TotalMemory = $TotalMemory -replace ("MB", "")
$TotalMemory | Set-Content ".buildtxtram.txt"
收集RAM。工作正常。问题是我有一个使用俄罗斯版本的Windows的用户,输出是俄语。我有什么办法可以强迫systeminfo
对英语的输出,因此可以解析?
至少在同一Windows版本中SystemInfo的标题计数应该相同。
因此,使用/FO csv
和/NH
选项,您可以以CSV格式强制输出,而无需标题,并提供英文版本或编号列,即
Windows 10英语与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
我不知道如何为sysinfo设置语言,但是还有其他方法可以获取相同的信息。这将使CIM_Computersystem类报告RAM。该数字在字节中报告,因此除以1GB
,在GB中给出了该数字。[ grin ]
$Ram_GB = [math]::Round((Get-CimInstance -ClassName CIM_ComputerSystem).TotalPhysicalMemory / 1GB, 2)
$Ram_GB
输出=我的系统上的8
。
对我来说,解决方法可以替换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 *