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?
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
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
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
}
}
$servers = Get-Content -Path “servers.txt”
$results = foreach ($server in $servers) {
Get-SystemInfo -ComputerName $server
}
$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
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).
how about this one? can you tell me anything wrong with this?
$computersFile = “C:\users\m338095\scripts\vm-not-found.txt”
$outputFile = “C:\users\m338095\scripts\vm-not-found.csv”
$computers = Get-Content $computersFile
$credential = Import-Clixml .\creds.cred
$results = @()
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
}
}
$results | Export-Csv -Path $outputFile -NoTypeInformation -Encoding UTF8
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 1 <---- Click
BTW: Sometimes the preformatted text button hides behind the gear symbol.