none
powershell script to get hardware info RRS feed

  • Question

  • Hi Team

    I would like to get the following information from a predefined list (text file) of computers on our network. 

    • make
    • model
    • RAM
    • OS
    • CPU
    • current user logged on

    The results can be output to a CSV file,please assist

    Thanks 

    Ivan

    Thursday, June 11, 2015 6:24 AM

Answers

  • Hello Ivan,

    Here is a PowerShell script that may suit your needs. I commented it so you can understand it easily if you're new to PowerShell :

    #Specify the path the text file containing the computer names
    $computers = Get-Content -Path "c:\computers.txt"
    
    # Creating an empty array, will be used later
    $array= @()
    
    
    foreach ($computer in $computers)
    {
        #Querying information about the computer
        $query = Get-WmiObject -Class win32_computersystem -ComputerName $computer
        $name = $query.Name
        $make = $query.Manufacturer
        $model = $query.Model
        $ram = $query.TotalPhysicalMemory/1Gb
        $os = (Get-WmiObject -Class win32_operatingsystem -ComputerName $computer).Caption
        $cpu = (Get-WmiObject -Class Win32_processor -ComputerName $computer).Name
        $users = $query.Username
    
        # Now creating an populating the array. Change the collumns name if you wish
        $Object = New-Object PSObject
        $Object | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $name
        $Object | Add-Member -MemberType NoteProperty -Name "Make" -Value $make
        $Object | Add-Member -MemberType NoteProperty -Name "Model" -Value $model
        $Object | Add-Member -MemberType NoteProperty -Name "RAM" -Value $ram
        $Object | Add-Member -MemberType NoteProperty -Name "OS" -Value $os
        $Object | Add-Member -MemberType NoteProperty -Name "CPU" -Value $cpu
        $Object | Add-Member -MemberType NoteProperty -Name "LoggedOnUsers" -Value $users
        $array += $Object
    }
    
    # Now exporting the array to a CSV file
    $array | Export-Csv -Path c:\test.csv -NoTypeInformation


    Simply adapt the path to your text file, and the path to the resulted CSV file. For this script to work, you need to have permissions to performs remote WMI queries on the computers listed in your text file.

    Hope this helps !


    Thursday, June 11, 2015 8:11 AM

All replies

  • type: systeminfo /FO CSV


    \_(ツ)_/

    Thursday, June 11, 2015 6:44 AM
  • Hello Ivan,

    Here is a PowerShell script that may suit your needs. I commented it so you can understand it easily if you're new to PowerShell :

    #Specify the path the text file containing the computer names
    $computers = Get-Content -Path "c:\computers.txt"
    
    # Creating an empty array, will be used later
    $array= @()
    
    
    foreach ($computer in $computers)
    {
        #Querying information about the computer
        $query = Get-WmiObject -Class win32_computersystem -ComputerName $computer
        $name = $query.Name
        $make = $query.Manufacturer
        $model = $query.Model
        $ram = $query.TotalPhysicalMemory/1Gb
        $os = (Get-WmiObject -Class win32_operatingsystem -ComputerName $computer).Caption
        $cpu = (Get-WmiObject -Class Win32_processor -ComputerName $computer).Name
        $users = $query.Username
    
        # Now creating an populating the array. Change the collumns name if you wish
        $Object = New-Object PSObject
        $Object | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $name
        $Object | Add-Member -MemberType NoteProperty -Name "Make" -Value $make
        $Object | Add-Member -MemberType NoteProperty -Name "Model" -Value $model
        $Object | Add-Member -MemberType NoteProperty -Name "RAM" -Value $ram
        $Object | Add-Member -MemberType NoteProperty -Name "OS" -Value $os
        $Object | Add-Member -MemberType NoteProperty -Name "CPU" -Value $cpu
        $Object | Add-Member -MemberType NoteProperty -Name "LoggedOnUsers" -Value $users
        $array += $Object
    }
    
    # Now exporting the array to a CSV file
    $array | Export-Csv -Path c:\test.csv -NoTypeInformation


    Simply adapt the path to your text file, and the path to the resulted CSV file. For this script to work, you need to have permissions to performs remote WMI queries on the computers listed in your text file.

    Hope this helps !


    Thursday, June 11, 2015 8:11 AM
  • Hi Antoine

    Thanks for your help,it is appreciated!

    Thursday, June 11, 2015 9:04 AM