Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. # Get All PCs in Domain, Export to ServerList.txt
  2. # Call get-inventory.ps1 logic on created Serverlist.txt
  3. # dk / 22.09.2017
  4. import-module activedirectory
  5.  
  6. $domain = "carpentier.local"
  7. $tempfile = "c:\temp\tmpfile.csv"
  8. $outfile = "c:\temp\Serverlist.csv"
  9. Get-ADComputer -Filter * |
  10. select-object Name |
  11. Export-CSV -NoTypeInformation $tempfile
  12.  
  13. #Clean up outfile
  14. $clean = Get-Content $tempfile
  15. $clean[1..$clean.count] |
  16. Set-Content $tempfile
  17. cat $tempfile |
  18. %{$_ -replace '"',''} |
  19. Set-Content $outfile
  20.  
  21. # Do the magic
  22. $servers = Get-Content $outfile
  23. $infoColl = @()
  24. Foreach ($s in $servers)
  25. {
  26. $CPUInfo = Get-WmiObject Win32_Processor -ComputerName $s #Get CPU Information
  27. $OSInfo = Get-WmiObject Win32_OperatingSystem -ComputerName $s #Get OS Information
  28. #Get Memory Information. The data will be shown in a table as MB, rounded to the nearest second decimal.
  29. $OSTotalVirtualMemory = [math]::round($OSInfo.TotalVirtualMemorySize / 1MB, 2)
  30. $OSTotalVisibleMemory = [math]::round(($OSInfo.TotalVisibleMemorySize / 1MB), 2)
  31. $PhysicalMemory = Get-WmiObject CIM_PhysicalMemory -ComputerName $s | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) }
  32. Foreach ($CPU in $CPUInfo)
  33. {
  34. $infoObject = New-Object PSObject
  35. #The following add data to the infoObjects.
  36. Add-Member -inputObject $infoObject -memberType NoteProperty -name "ServerName" -value $CPU.SystemName
  37. Add-Member -inputObject $infoObject -memberType NoteProperty -name "Processor" -value $CPU.Name
  38. Add-Member -inputObject $infoObject -memberType NoteProperty -name "Model" -value $CPU.Description
  39. Add-Member -inputObject $infoObject -memberType NoteProperty -name "Manufacturer" -value $CPU.Manufacturer
  40. Add-Member -inputObject $infoObject -memberType NoteProperty -name "PhysicalCores" -value $CPU.NumberOfCores
  41. Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L2CacheSize" -value $CPU.L2CacheSize
  42. Add-Member -inputObject $infoObject -memberType NoteProperty -name "CPU_L3CacheSize" -value $CPU.L3CacheSize
  43. Add-Member -inputObject $infoObject -memberType NoteProperty -name "Sockets" -value $CPU.SocketDesignation
  44. Add-Member -inputObject $infoObject -memberType NoteProperty -name "LogicalCores" -value $CPU.NumberOfLogicalProcessors
  45. Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Name" -value $OSInfo.Caption
  46. Add-Member -inputObject $infoObject -memberType NoteProperty -name "OS_Version" -value $OSInfo.Version
  47. Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalPhysical_Memory_GB" -value $PhysicalMemory
  48. Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVirtual_Memory_MB" -value $OSTotalVirtualMemory
  49. Add-Member -inputObject $infoObject -memberType NoteProperty -name "TotalVisable_Memory_MB" -value $OSTotalVisibleMemory
  50. $infoObject #Output to the screen for a visual feedback.
  51. $infoColl += $infoObject
  52. }
  53. }
  54. #Export the results in csv file in c:\temp.
  55. $infoColl | Export-Csv -path c:\temp\Server_Inventory_$((Get-Date).ToString('MM-dd-yyyy')).csv -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement