Get Server Inventory: CPU, Memory, and OS information. Export to CSV.

Script requested: "I'm looking for a script that will bring me the information of memory, cpu, core, processor type and operating system, from a list of servers and this information should be printed to a file output"The script will get the CPU specifications, memory usage stati

 
 
 
 
 
4 Star
(15)
34,301 times
Add to favorites
Hardware
3/8/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • For some reason the script is returning duplicate values. can you take a look and see why it is runnign the script twice on every server int he .txt file
    1 Posts | Last post March 16, 2019
    • #Get the server list
      $servers = Get-Content "C:\security\Scripts\Cores_processors\ServerList.txt"
      #Run the commands for each server in the list
      $infoColl = @()
      Foreach ($s in $servers)
      {
         
      	$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s #Get CPU Information
      	$OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s #Get OS Information
      	#Get Memory Information. The data will be shown in a table as MB, rounded to the nearest second decimal.
      	$OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2)
      	$OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1MB), 2)
      	$PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) }
      	Foreach ($CPU in $CPUInfo)
      	{
      		$infoObject = New-Object PSObject
      		#The following add data to the infoObjects.	
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $CPU.Name
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Model" -value $CPU.Description
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer" -value $CPU.Manufacturer
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "PhysicalCores" -value $CPU.NumberOfCores
      		Add-M
  • Can't run the script because of Serverlist.txt
    1 Posts | Last post May 13, 2018
    • i create the Serverlist.txt, but when i run the script it keeps tell me "Get-Content : Cannot find path 'C:\HealthCheck\Serverlist.txt' because it does not exist."
  • CSV. FILE
    1 Posts | Last post December 14, 2017
    • How do I find the csv file that will be created?
  • Getting Drive Information also
    1 Posts | Last post November 21, 2017
    • How would I get Drive Information also on this Script.
      
      For Example if we have 30 servers with different drives just want to know the Capacity and the Freespace.
  • Can you include a if/else statement that queries if the machine is online before it connects?
    1 Posts | Last post November 11, 2017
    • I'm using this to gather info about all of the machines in my environment in preparation to upgrade from windows 7 to windows 10. When a machine is offline it severely slows the rate at which the script runs. Otherwise, I find it quite useful. Thanks! 
  • .
    3 Posts | Last post June 28, 2017
    • Did you get a chance to work on this script..!!
    • Work on what exactly?
    • requriemnt is to find disksize in multiple server . your script is working fine and even calculations are also. But $dskinfo (disko" -value $Disk) it is showing null . please share you idea.
      $dskinfo= get-WmiObject win32_logicaldisk -Computername $s
      
        $Disk = [math]::round($dskinfo.Size / 1gb, 2)
      
      Add-Member -inputObject $infoObject -memberType NoteProperty -name "disko" -value $Disk
      
      
  • Can you also include Harddisk details
    1 Posts | Last post April 10, 2017
    • Can you also include harddisk details like Total, C drive etc. Thanks
  • PF and volume.
    1 Posts | Last post March 07, 2017
    • Hi KornKolio,
      
      I need get page file and volumes information (total space, free space and letter)
      
      Thanks.-
  • seems to be overwriting itself when exportin to csv
    4 Posts | Last post March 06, 2017
    • I ran this script and it seems that it might be overwritting itself when it exports the info to csv. The only data in the csv was the last server it scanned. 
    • Greetings Joshua,
      Thank you for letting me know!
      This is one of the first lines I wrote in PS and it seems that things are missing...
      I've corrected and updated the script.
      Cheerz
    • Getting RPC server unavailable. Please help me if some body can resolve this. 
    • Hi Team, 
      
      Please ignore, I've resolved this issue.
      Thanks.
  • server.txt list content
    15 Posts | Last post March 02, 2017
    • sorry for asking a really stupid question, but what exactly is the content of the server.txt. Is it just an exported list of computer names on the computer and servers on a domain? Does it matter how the file is formatted at all?
    • Hello, it is a plain text file, the only rule is that the hosts should be on separate lines.
    • Cool, cheers.
      How would I get the IP address of the hosts as well?
    • Cheers! For the WMI version of the script you may try this (will resolve the IPv4 address):
      
      #Get the server list
      $servers = Get-Content .\Serverlist.txt
      #Run the commands for each server in the list
      $infoColl = @()
      Foreach ($s in $servers)
      {
      	$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s #Get CPU Information
      	$OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s #Get OS Information
      	#Get Memory Information. The data will be shown in a table as MB, rounded to the nearest second decimal.
      	$OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2)
      	$OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1MB), 2)
      	$PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) }
      	Foreach ($CPU in $CPUInfo)
      	{
      		$infoObject = New-Object PSObject
      		#The following add data to the infoObjects.	
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $CPU.Name
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Model" -value $CPU.Description
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer" -value $CPU.Manufacturer
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "PhysicalCores" -value $CPU.NumberOfCores
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L2CacheSize" -value $CPU.L2CacheSize
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L3CacheSize" -value $CPU.L3CacheSize
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Sockets" -value $CPU.SocketDesignation
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "LogicalCores" -value $CPU.NumberOfLogicalProcessors
    • Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Name" -value $OSInfo.Caption
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Version" -value $OSInfo.Version
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalPhysical_Memory_GB" -value $PhysicalMemory
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVirtual_Memory_MB" -value $OSTotalVirtualMemory
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVisable_Memory_MB" -value $OSTotalVisibleMemory
      		$infoObject #Output to the screen for a visual feedback.
      		$infoColl += $infoObject
      	}
      }
      $infoColl | Export-Csv -path .\Server_Inventory_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation #Export the results in csv file.
    • I'm sorry, I've just copied the original code :)
      Here is the updated one:
      
      #Get the server list
      $servers = Get-Content .\Serverlist.txt
      #Run the commands for each server in the list
      $infoColl = @()
      Foreach ($s in $servers)
      {
      	$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s #Get CPU Information
      	$OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s #Get OS Information
      	#Get Memory Information. The data will be shown in a table as MB, rounded to the nearest second decimal.
      	$OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2)
      	$OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1MB), 2)
      	$PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) }
          $IPAddress = Get-WmiObject win32_Networkadapterconfiguration | Where-Object {$_.ipaddress -notlike $null}
      	Foreach ($CPU in $CPUInfo)
      	{
      		$infoObject = New-Object PSObject
      		#The following add data to the infoObjects.	
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName
              Add-Member -inputObject $infoObject -memberType NoteProperty -name "IPv4_Address" -value $CPU.Name
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $IPAddress.IPaddress[0]
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Model" -value $CPU.Description
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer" -value $CPU.Manufacturer
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "PhysicalCores" -value $CPU.NumberOfCores
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L2CacheSize" -value $CPU.L2CacheSize
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L3CacheSize" -value $CPU.L3CacheSize
    • 		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Sockets" -value $CPU.SocketDesignation
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "LogicalCores" -value $CPU.NumberOfLogicalProcessors
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Name" -value $OSInfo.Caption
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Version" -value $OSInfo.Version
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalPhysical_Memory_GB" -value $PhysicalMemory
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVirtual_Memory_MB" -value $OSTotalVirtualMemory
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVisable_Memory_MB" -value $OSTotalVisibleMemory
      		$infoObject #Output to the screen for a visual feedback.
      		$infoColl += $infoObject
      	}
      }
      $infoColl | Export-Csv -path .\Server_Inventory_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation #Export the results in csv file.
    • Again wrong, and finally:
      
      #Get the server list
      $servers = Get-Content .\Serverlist.txt
      #Run the commands for each server in the list
      $infoColl = @()
      Foreach ($s in $servers)
      {
      	$CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s #Get CPU Information
      	$OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s #Get OS Information
      	#Get Memory Information. The data will be shown in a table as MB, rounded to the nearest second decimal.
      	$OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2)
      	$OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1MB), 2)
      	$PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) }
          $IPAddress = Get-WmiObject win32_Networkadapterconfiguration | Where-Object {$_.ipaddress -notlike $null}
      	Foreach ($CPU in $CPUInfo)
      	{
      		$infoObject = New-Object PSObject
      		#The following add data to the infoObjects.	
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName
              Add-Member -inputObject $infoObject -memberType NoteProperty -name "IPv4_Address" -value $IPAddress.IPaddress[0]
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $CPU.Name
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Model" -value $CPU.Description
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer" -value $CPU.Manufacturer
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "PhysicalCores" -value $CPU.NumberOfCores
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L2CacheSize" -value $CPU.L2CacheSize
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L3CacheSize" -value $CPU.L3CacheSize
    • 		Add-Member -inputObject $infoObject -memberType NoteProperty -name "Sockets" -value $CPU.SocketDesignation
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "LogicalCores" -value $CPU.NumberOfLogicalProcessors
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Name" -value $OSInfo.Caption
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Version" -value $OSInfo.Version
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalPhysical_Memory_GB" -value $PhysicalMemory
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVirtual_Memory_MB" -value $OSTotalVirtualMemory
      		Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVisable_Memory_MB" -value $OSTotalVisibleMemory
      		$infoObject #Output to the screen for a visual feedback.
      		$infoColl += $infoObject
      	}
      }
      $infoColl | Export-Csv -path .\Server_Inventory_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation #Export the results in csv file.
    • Cool, cheers.
    • Hi, I've run this and it's given the same IPV4 address for all computers.
    • Sorry, I was overloaded with stuff and obviously provided wrong code.
      Please change the following line:
      $IPAddress = Get-WmiObject win32_Networkadapterconfiguration | Where-Object {$_.ipaddress -notlike $null}
      with:
      $IPAddress = Get-WmiObject win32_Networkadapterconfiguration -ComputerName $s Where-Object {$_.ipaddress -notlike $null}
    • and add pipe | before Where-Object
    • :D
    • That's great - thanks a lot :)
1 - 10 of 16 Items