PowerShell - Get SysInfo from text list of Computers
- Jon Boyette
- Jan 11, 2022
- 1 min read
Save as a namdedps1, Populate c:\temp\servers.txt with ALL servers to check/get sysinfo. Outputs to c:\temp\ServerDiscovery.csv, Includes - ComputerName, Make, Model, RAM, OS, CPU, LoggedOnUsers
#Specify the path the text file containing the computer names
$computers = Get-Content -Path "c:\temp\servers.txt"
# Creating an empty array, will be used later
$array= @()
foreach ($computer in $computers)
{
#Querying information about the computer
$query = Get-WmiObject -Class win32_computersystem -ComputerName $computer
$name = $query.Name
$make = $query.Manufacturer
$model = $query.Model
$ram = $query.TotalPhysicalMemory/1Gb
$os = (Get-WmiObject -Class win32_operatingsystem -ComputerName $computer).Caption
$cpu = (Get-WmiObject -Class Win32_processor -ComputerName $computer).Name
$users = $query.Username
# Now creating an populating the array. Change the collumns name if you wish
$Object = New-Object PSObject
$Object | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $name
$Object | Add-Member -MemberType NoteProperty -Name "Make" -Value $make
$Object | Add-Member -MemberType NoteProperty -Name "Model" -Value $model
$Object | Add-Member -MemberType NoteProperty -Name "RAM" -Value $ram
$Object | Add-Member -MemberType NoteProperty -Name "OS" -Value $os
$Object | Add-Member -MemberType NoteProperty -Name "CPU" -Value $cpu
$Object | Add-Member -MemberType NoteProperty -Name "LoggedOnUsers" -Value $users
$array += $Object
}
# Now exporting the array to a CSV file
$array | Export-Csv -Path c:\temp\ServerDiscovery.csv -NoTypeInformation
Comments