PowerShell Script to get Servers info from the inventory list

Oleg Aronov 106 Reputation points


I wonder if someone can help me with PowerShell script to gather Servers info from my inventory list.

I need to collect some hardware/software information for remote servers on my list that I have already. How can I approach it?

Ideally I need as mush data as possible - OS, Built Date, UpTime, Space Used/Left, Last Reboot, Last Logon User and etc.

I should be able to provide credentials for login.
Of course, would be nice to check first if the server is reachable or not.

Is it doable? Any ideas where/how to start?

Thank you!

Microsoft System Center
Microsoft System Center
A suite of Microsoft systems management products that offer solutions for managing datacenter resources, private clouds, and client devices.
883 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,410 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,431 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Rich Matheisen 45,416 Reputation points

    Is it doable? Sure. At least most of it. Start with this:

    Get-Content InventoryListOfServerNames.txt |
            $x = Get-CimInstance -ComputerName $_ -ClassName win32_operatingsystem
            $y = Get-CimInstance -ComputerName $_-ClassName win32_logicaldisk -Filter "DriveType = 3"
            # fill in name/data pairs as needed
                Name = Value

    The "Last Logon User" is unclear. Do you mean the last user to logon the machine from its console? Or interactively? Using RDP? There are many different types of logons. Each logon should be recorded in the machine's security log.

  2. Andreas Baumgarten 99,466 Reputation points MVP

    Hi @Oleg Aronov ,

    in addition to Rich:
    You can test the connection to the server like this (add the line between line 2 and 3 of Rich's script and add a } at the end):

    if (Test-Connection -TargetName $_ -Quiet) { # line 3 - 8 of Rich's script }  



    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

  3. AlexZhu-MSFT 5,551 Reputation points Microsoft Vendor


    For Linux computers, we may use ssh connection to get the information we needed.

    Here's a sample for retrieveing OS info and cpu usage from linux computers. Just to illustrate how it works and we need to change it to cater for the actual environment.

    Get-Content InventoryListOfServerNames.txt |  
    		if (Test-Connection -computername $_ -Quiet)  
    			$computer = $_  
    			$os_info = ssh root@$computer "uname -a"  
    			$cpu_usage_linux = ssh root@$computer "top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 | gawk '{print `$2+`$4+`$6}'"  


    Note: we need to setup passwordless ssh connect before running the script.
    Note: This is not from Microsoft, just for your reference

    If the response is helpful, please click "Accept Answer" and upvote it.