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

**URL:** <https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281>\
**Category:** PowerShell Help\
**Created:** [May 11, 2023, 1:12pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281 "2023-05-11T13:12:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tdubb123](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tdubb123/32/3925_2.png) [@tdubb123](https://forums.powershell.org/u/tdubb123)\
**Post date:** [May 11, 2023, 1:12pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/1 "2023-05-11T13:12:58Z")

</div>

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  
Memory

# CPUS

any idea how to get this?

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 11, 2023, 1:30pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/2 "2023-05-11T13:30:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![tdubb123](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tdubb123/32/3925_2.png) [@tdubb123](https://forums.powershell.org/u/tdubb123)\
**Post date:** [May 11, 2023, 1:57pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/3 "2023-05-11T13:57:27Z")

</div>

i try this but it is not working

# Define a function to get the system information

function Get-SystemInfo {  
param (  
[string]$ComputerName  
)

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

# 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
[PSCustomObject]@{
    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

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 11, 2023, 2:29pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/4 "2023-05-11T14:29:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![neemobeer](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/neemobeer/32/4087_2.png) [@neemobeer](https://forums.powershell.org/u/neemobeer)\
**Post date:** [May 11, 2023, 2:33pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/5 "2023-05-11T14:33:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tonyd](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tonyd/32/1041_2.png) [@tonyd](https://forums.powershell.org/u/tonyd)\
**Post date:** [May 11, 2023, 3:30pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/6 "2023-05-11T15:30:51Z")

</div>

> [@tdubb123](#):
>
> `Get-WmiObject`

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).

---

<div class="post-metadata">

**Author:** ![tdubb123](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tdubb123/32/3925_2.png) [@tdubb123](https://forums.powershell.org/u/tdubb123)\
**Post date:** [May 12, 2023, 12:59pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/7 "2023-05-12T12:59:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [May 12, 2023, 2:50pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/8 "2023-05-12T14:50:21Z")

</div>

Tdubb123,  
Welcome to the forum. 👋🏼

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 PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) 1 \<---- Click 👆🏽 😉

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:14pm UTC](https://forums.powershell.org/t/got-a-list-of-servers-and-need-to-get-these-info-remotely/22281/9 "2024-05-16T20:14:55Z")

</div>


