PowerShell script to report on computer inventory

Back in October of 2014 I responded to a TechNet Script Center Repository Request


The script I wrote back then looked like:


Based on user feedback I decided to update this script. Version 2 is now online. Enhancements in version 2 include:

  • Powershell 2.0 compatibility (Windows 7 and Server 2008 native, Windows 2003 and Windows XP possible)
  • Script version 2 is backward compatible with script version 1 in the sense that example are provided to use script v2 to produce same output as script v1
  • Both scripts return output as a PS Object which lends itself handy to further automation
  • Added -Verbose output, removed ‘log’ function
  • Added more information for computer object:
    •  Manufacturer – example : Microsoft Corporation
    • OSCaption – example : Microsoft Windows 7 Professional
    • VirtualMachine  : True or False
    • OSArchitecture – example : 64-bit

Example 1


The script returns a PS object similar to:


Example 2

.\Ping-Report-v2.ps1 -ComputerName $env:COMPUTERNAME,bla1,p-2012r2-sb1

Possible output:


This example shows output when a computer is down, and when the script is run under a user context that has no permission/access to query the target computer(s)

Example 3

The same can be done reading the computer list from a CVS file as in:

Import-Csv .\Computerlist.csv | 
  % { .\Ping-Report-v2.ps1 $_.ComputerName }

The input CSV file may look like:


Example 4

The output can be exported to CSV to file as in:

Import-Csv .\Computerlist.csv | 
  % { .\Ping-Report-v2.ps1 $_.ComputerName } | 
    select ComputerName, Status, OSCaption, VirtualMachine, IPAddress |
      Export-Csv z:report1.csv -NoType


Example 5

.\Ping-Report-v2.ps1 V-WIN7PROX64,bla1,V-WIN7PROX64,p-2012r2-sb1 | 
    select ComputerName, Status, OSCaption, VirtualMachine, IPAddress | FT -a





3 responses

  1. Justin Riggs

    This is great but I’ve had lots of problems with Test-Connection. I prefer:

    $ping = New-Object System.Net.NetworkInformation.Ping

    In my environment this returns info on 1/3 more systems than Test-Connection.

    January 25, 2017 at 6:31 pm

  2. Tyler J Canine

    Trying to run this and I get the error:

    At C:\Users\175020\Desktop\Ping-Report-v2.ps1:14 char:1
    + [CmdletBinding(ConfirmImpact=’Low’)]
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Unexpected attribute ‘CmdletBinding’.
    At C:\Users\175020\Desktop\Ping-Report-v2.ps1:15 char:1
    + Param([Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipeline …
    + ~~~~~
    Unexpected token ‘Param’ in expression or statement.
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedAttribute

    March 7, 2017 at 11:49 am

  3. Joe Glim

    If a machine refuses the Get-WMIObject query for the default credentials, is it possible to have a list of possible credentials that could be tried (programatically).

    June 8, 2017 at 10:19 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s