PowerShell to get system information from remote computers

Last updated on 16th January 2017

This is a very useful PowerShell script for system administrators / network administrators to automatically create an inventory list of devices. This script reads a list of computer names or IP addresses from a CSV file and remotely gets the system information such as System name, Operating system details, disk capacity details, network information etc., The output is printed on the screen and also written into a CSV file.

To run the script you need to pass two parameters - an input csv file and an output csv file with full path. See example below:

PS C:\> Get-SysInfo c:\IPaddressList.csv c:\SysInfo.csv

The input csv file must contain a column with header ComputerName that contains the list of host names or IP addresses. Column header name is set in the variable $ColumnHeader. For each of the computers in the list, the script will get instances of Windows Management Instrumentation (WMI) classes using the Get-WmiObject PowerShell cmdlet. The information that we want collect comes from three WMI classes - Win32_OperatingSystem, Win32_Volume and Win32_NetworkAdapterConfiguration. The collected information is stored in a Hash table which is basically a collection of name value pairs. We then create a PowerShell object with name in Hash table as Property Name and the value in hash table as Property Value. Finally the new PowerShell object is output to CSV file using Export-CSV cmdlet.


<#

.SYNOPSIS
  Powershell script to get system information from remote computers.
  
.DESCRIPTION
  This PowerShell script reads a list of computer names (or IP Addresses)
  from a CSV file and remotely gets the system information related to its
  Operating System, Disk and network. The output is written to a another
  CSV file in table format. 
  
.PARAMETER <infile>
   File name and path of the input CSV file to read.

.PARAMETER <outfile>
   File name and path of the outout CSV file.
 
.NOTES
  Version:        1.0
  Author:         Open Tech Guides
  Creation Date:  16-Jan-2017
 
.LINK
    www.opentechguides.com
    
.EXAMPLE
  Get-SysInfo c:\IPaddressList.csv c:\SysInfo.csv
   
#>

Param(
  [Parameter(Mandatory=$true, position=0)][string]$infile,
  [Parameter(Mandatory=$true, position=1)][string]$outfile
)

#Column header in input CSV file that contains the host name 
$ColumnHeader = "ComputerName"
$HostList = import-csv $infile | select-object $ColumnHeader
$out = @()

foreach($object in $HostList) {
    
    $os = Get-WmiObject -computername $object.("ComputerName") -class win32_operatingsystem
    $vol = Get-WmiObject -computername $object.("ComputerName") -class Win32_Volume
    $net = Get-WmiObject -computername $object.("ComputerName") -class Win32_NetworkAdapterConfiguration | where-object { $_.IPAddress -ne $null }

    $DeviceInfo= @{}
    $DeviceInfo.add("Operating System", $os.name.split("|")[0])
    $DeviceInfo.add("Version", $os.Version)
    $DeviceInfo.add("Architecture", $os.OSArchitecture)
    $DeviceInfo.add("Serial Number", $os.SerialNumber)
    $DeviceInfo.add("Organization", $os.Organization)
    $DeviceInfo.add("Disk Capacity", "$([math]::floor($vol.Capacity/ (1024 * 1024 * 1024 )) )" + " GB" )
    $DeviceInfo.add("Free Capacity", "$([math]::floor($vol.FreeSpace/ (1024 * 1024 * 1024 )))" + " GB" )
    $DeviceInfo.add("System Name", $vol.SystemName)
    $DeviceInfo.add("File System", $vol.FileSystem)
    $DeviceInfo.add("IP Address", ($net.IPAddress -join (", ")))
    $DeviceInfo.add("Subnet", ($net.IPSubnet  -join (", ")))
    $DeviceInfo.add("MAC Address", $net.MACAddress )

    $out += New-Object PSObject -Property $DeviceInfo | Select-Object `
              "System Name", "Organization", "Serial Number","Operating System", `
              "Version","Architecture","File System","Disk Capacity", `
              "Free Capacity","MAC Address","IP Address","Subnet"

    Write-Verbose ($out | Out-String) -Verbose             
    $out | Export-CSV $outfile -NoTypeInformation
 }
 

Here is a sample input file IPAddressList.csv containing IP addresses and host names. Note the column header is "ComputerName". If you want to use a different column header then change the $ColumnHeader variable accoringly.

IP Address list
IPAddressList.csv

Below is the output file that script generates.

System Info
SysInfo.csv

If the output CSV file that you pass as argument already exists, then it will be overwritten. If the file doesn't exist then it will be created.


Post a comment

Comments

ajinkya | April 2, 2019 9:49 AM |

disk space is not showing in the output file pls suggest.

Mike Franklin | October 3, 2024 6:36 PM |

I did this instead. $DeviceInfo.add("Disk Capacity", (Get-CimInstance Win32_LogicalDisk | where-object -property DriveType -eq 3 | Select-Object -Property DeviceID, Size, Freespace))

sam | October 4, 2022 8:03 AM |

any option to get monitor serial number and model?

Ado | October 26, 2018 11:25 AM |

Thanks for providing this. I used the Win32_ComputerSystem class instead of Win32_Volume to grab the Hostname of the systems. $sys = Get-WmiObject -computername $object.("ComputerName") -class Win32_ComputerSystem and then $DeviceInfo.add("Hostname", $sys.DNSHostName) ..when dealing with machines with multiple Volumes, this stops the script from displaying one hostname per volume.

Tosin | July 13, 2021 12:57 PM |

Thanks!

Steve | July 27, 2020 9:51 PM |

I must be doing something incorrectly. The result for me is that it provides sub-net and IP Address, System Type, etc., but it doesn't resolve the Computer Name with the IP address....

Patty P. | November 17, 2019 10:46 PM |

Is there a way to also pass a user/password on the Get-WmiObject line?

Patrick | November 19, 2019 10:25 AM |

yes you can pass username and password to Get-WmiObject, First you need to create a PSCredential object and passs it to the -credential parameter. $secpasswd = ConvertTo-SecureString "PlainTextPassword" -AsPlainText -Force $mycreds = New-Object System.Management.Automation.PSCredential ("username", $secpasswd) Get-WmiObject -Credential $mycreds

Guy | April 2, 2019 8:41 PM |

I would like to see what the whole script looks like on your PS session. Thank you in advance.

Ado | October 26, 2018 11:25 AM |

Thanks for providing this. I used the Win32_ComputerSystem class instead of Win32_Volume to grab the Hostname of the systems. $sys = Get-WmiObject -computername $object.("ComputerName") -class Win32_ComputerSystem and then $DeviceInfo.add("Hostname", $sys.DNSHostName) ..when dealing with machines with multiple Volumes, this stops the script from displaying one hostname per volume.

Mike | September 7, 2018 6:33 PM |

anyway to also get RAM output?

Ben | November 21, 2017 8:36 PM |

I'm having trouble with the "Get-" cmdlet. I am using Powershell on a machine running Windows Server 2008 should this be an issue?