How to format batch command result on text file

后端 未结 4 1159
清歌不尽
清歌不尽 2020-12-07 06:31

I am retrieving computer information using the batch script below,

(
    systeminfo | findstr /c:\"Host Name\" /c:\"Domain\" /c:\"OS Name\" /c:\"OS Version\"         


        
4条回答
  •  旧巷少年郎
    2020-12-07 06:45

    Here's an untested PowerShell version, only because of how long systeminfo takes:

    PCInfo.ps1

    $Properties = @{  
      Host_Name = (GWMI Win32_OperatingSystem).CSName
      OS_Name = (GWMI Win32_OperatingSystem).Caption
      OS_Version = GWMI Win32_OperatingSystem | % {$_.Version+' build '+$_.BuildNumber}
      System_Manufacturer = (GWMI Win32_ComputerSystem).Manufacturer
      System_Model = (GWMI Win32_Computersystem).Model
      BIOS_Version = (GWMI Win32_BIOS).SMBIOSBIOSVersion
      Total_Physical_Memory = GWMI Win32_PhysicalMemory | Measure Capacity -Sum | % {[String]$([Math]::Round(($_.Sum / 1MB),0))+' MB'}
      Available_Physical_Memory = GWMI Win32_OperatingSystem | % {[String]$([Math]::Round(($_.FreePhysicalMemory * 1KB / 1MB),0))+' MB'}
      Domain = GWMI Win32_Computersystem | % {$_.DNSHostName +'.'+$_.Domain}
      Serial_Number = (GWMI Win32_BIOS).SerialNumber}
    $ColumnWidth = ($Properties.Keys | Measure -Max Length).Maximum
    $Properties.GetEnumerator() | Sort Name| % {"{0,-$ColumnWidth}: {1}" -F $_.Key, $_.Value}
    

    To run it, change the paths as necessary and enter the following at the Command Prompt:

    PowerShell -NoP -ExecutionPolicy RemoteSigned -File "C:\Users\YHTAN\Desktop\PCInfo.ps1">"C:\Users\YHTAN\Desktop\PCInfo.txt"
    

提交回复
热议问题