Search code examples
windowspowershellcommand-line-interfacesystem-information

Get system information from command line interface


I'm trying to create a script, that when run, will output a text file of that computer's specs.

Is there a program that offers command line interface to generating a text file containing simplified computer specifications on a Windows OS?

Just the basic consumer info. ie: RAM, CPU, HDD, etc.. I don't need or want every last detail about the computer.

I understand that MSinfo32, DxDiag, Speccy, offer export features however Speccy doesn't offer automation through CLI, and the other two simply export a glob of all system info. Much of which is personal and unnecessary for what I need.

The only two workarounds I can think of is to either use a Windows equivalent of a grep/cat/awk command to sift out only the necessary info. Which could prove to be quite tedious seeing as how each system would, obviously, have different specs. Alternatively, use a program (if one exists) to specify which specs to gather and which ones to leave out.


Solution

  • In powershell:

    $System = Get-CimInstance CIM_ComputerSystem
    $BIOS = Get-CimInstance CIM_BIOSElement
    $OS = Get-CimInstance CIM_OperatingSystem
    $CPU = Get-CimInstance CIM_Processor
    $HDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
    $EXTXT = "$env:USERPROFILE\Desktop\welp.txt"
    Clear-Host
    
    "Manufacturer: " + $System.Manufacturer >> $EXTXT
    "Model: " + $System.Model >> $EXTXT
    "CPU: " + $CPU.Name >> $EXTXT
    "RAM: " + "{0:N2}" -f ($System.TotalPhysicalMemory/1GB) + "GB" >> $EXTXT
    "HDD Capacity: "  + "{0:N2}" -f ($HDD.Size/1GB) + "GB" >> $EXTXT
    "Operating System: " + $OS.caption >> $EXTXT
    

    The replies to my question got me better search results. Most of the source code is from here: http://community.spiceworks.com/scripts/show_download/1831
    I was able to piece together the appending and stuff afterwards. Save as .ps1 format and it's good to go.

    Or if you prefer here's the same, relative, script written in Python. Using native Windows and PowerShell commands.

    import os
    import wmi
    import math
    
    c = wmi.WMI()    
    SYSINFO = c.Win32_ComputerSystem()[0]
    OSINFO = c.Win32_OperatingSystem()[0]
    CPUINFO = c.Win32_Processor()[0]
    HDDINFO = c.Win32_LogicalDisk()[0]
    RAMINFO = c.Win32_PhysicalMemory()[0]
    
    MANUFACTURER = SYSINFO.Manufacturer
    MODEL = SYSINFO.Model
    RAMTOTAL = int(SYSINFO.TotalPhysicalMemory)
    HDDTOTAL = int(HDDINFO.size)
    RAMSIZE = round(RAMTOTAL)
    HDDSIZE = round(HDDTOTAL)
    
    os.system('cls')
    print "Model: " + MANUFACTURER + " " + MODEL
    print "\r"
    print "HDD: " + str(HDDTOTAL) + "GB"
    print "RAM: " + str(RAMTOTAL) + "GB"
    print "CPU: " + CPUINFO.name
    print "OS: " + OSINFO.caption