Got a list of servers and need to get these info remotely

I got a list of servers in txt file and I need to get following info from them and I think the only way is to do it through wmi. I do have credentials to login

OS version
IP Address


any idea how to get this?

This forum is for help with specific questions about scripts not answering something that is a simple web search. I suggest doing some research prior to asking for help here and show code that you’re working on.

i try this but it is not working

Define a function to get the system information

function Get-SystemInfo {
param (

# Check if the computer is alive
if (!(Test-Connection -ComputerName $ComputerName -Quiet -Count 1)) {
    Write-Host "$ComputerName is not responding." -ForegroundColor Yellow

# Get the system information
$os = Get-WmiObject -Class Win32_OperatingSystem
$ip = Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } | Select-Object -ExpandProperty IPAddress
$mem = [math]::Round($os.TotalVisibleMemorySize / 1MB, 2)
$cpus = (Get-WmiObject -Class Win32_Processor).Count
$manufacturer = (Get-WmiObject -Class Win32_ComputerSystem).Manufacturer

# Output the system information in a table format
    ComputerName = $ComputerName
    OperatingSystem = $os.Caption
    IPAddress = $ip
    Memory = "$mem GB"
    CPUs = $cpus
    Manufacturer = $manufacturer


Get the list of servers from a text file

$servers = Get-Content -Path “servers.txt”

Loop through each server and get the system information

$results = foreach ($server in $servers) {
Get-SystemInfo -ComputerName $server

Output the results in a table format

$results | Format-Table -AutoSize

What do you mean by “not working”? Output is blank, you get an error, you get the wrong data?

Looks like you’re querying the local system and not a remote system. I would suggest putting the system info code in a script block, passing it to the remote computer with Invoke-Command and returning the PSCustomObject

1 Like

You may also want to move to Get-CimInstance as Get-WmiObject has been deprecated. It also supports the -ComputerName parameter to query your remote systems (as does Get-WmiObject).

1 Like

how about this one? can you tell me anything wrong with this?

Define the path to the text file containing the list of computer names

$computersFile = “C:\users\m338095\scripts\vm-not-found.txt”

Define the path to the output file

$outputFile = “C:\users\m338095\scripts\vm-not-found.csv”

Read the list of computer names from the text file

$computers = Get-Content $computersFile

$credential = Import-Clixml .\creds.cred

Create an empty array to store the results

$results = @()

Loop through each computer in the list

foreach ($computer in $computers) {

# Test whether the computer is online by pinging it

$pingResult = Test-Connection -ComputerName $computer -Count 1 -Quiet

if ($pingResult) {

    # Retrieve network adapter configuration to get IP address

    $ipAddress = (Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $computer -Credential $credential | Where-Object {$_.IPAddress}).IPAddress[0]

    # Retrieve operating system information

    $os = Get-WmiObject Win32_OperatingSystem -ComputerName $computer -Credential $credential

    # Retrieve CPU information

    $cpu = Get-WmiObject Win32_Processor -ComputerName $computer -Credential $credential

    # Retrieve memory information

    $memory = Get-WmiObject Win32_PhysicalMemory -ComputerName $computer -Credential $credential | Measure-Object -Property capacity -Sum | Select-Object @{Name='CapacityGB';Expression={$_.Sum / 1GB}}

    # Add the results to the array

    $result = [PSCustomObject]@{

        ComputerName = $computer

        IPAddress = $ipAddress

        OperatingSystem = "$($os.Caption) $($os.Version)"

        CPU = $cpu.Name

        Memory = "$($memory.CapacityGB) GB"


    $results += $result


else {

    # Add a placeholder result to the array indicating that the computer is not online

    $result = [PSCustomObject]@{

        ComputerName = $computer

        IPAddress = "N/A"

        OperatingSystem = "N/A"

        CPU = "N/A"

        Memory = "N/A"


    $results += $result



Output the results to the output file in table format

$results | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8

Welcome to the forum. :wave:t3:

Your posts are hard t oto read. Could you please go back, edit at least your past again and fix the formatting of your code?

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in 1 <---- Click :point_up_2:t4: :wink:

BTW: Sometimes the preformatted text button hides behind the gear symbol. :wink: