Advertisement
Lee_Dailey

basic remote parallel SystemInfo demo script

Apr 3rd, 2019
2,989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #requires -RunAsAdministrator
  2.  
  3. # fake reading in a text file
  4. #    in real life, use Get-Content
  5. $ComputerList = @'
  6. LocalHost
  7. 10.0.0.1
  8. 127.0.0.1
  9. BetterNotBeThere
  10. '@ -split [environment]::NewLine
  11.  
  12. $TimeStamp = (Get-Date).ToString('yyyy-MM-dd_-_HH-mm-ss')
  13. $ReportPath = $env:TEMP
  14. $ReportFile = 'SystemReport_-_{0}.csv' -f $TimeStamp
  15. $FullReportFile = Join-Path -Path $ReportPath -ChildPath $ReportFile
  16.  
  17. $NoResponse = '_n/a_'
  18.  
  19. $IC_ScriptBlock = {
  20.     $CIM_CS = Get-CimInstance -ClassName CIM_ComputerSystem
  21.     $CIM_BE = Get-CimInstance -ClassName CIM_BIOSElement
  22.     $CIM_Processor = Get-CimInstance -ClassName CIM_Processor
  23.     $CIM_OS = Get-CimInstance -ClassName CIM_OperatingSystem
  24.     $CIM_Ram = Get-CimInstance -ClassName CIM_PhysicalMemory
  25.  
  26.     [PSCustomObject]@{
  27.         ComputerName = $CIM_CS.Name
  28.         ScanDate = [datetime]::Now.ToString('yyyy-MM-dd')
  29.         UserName = $CIM_CS.UserName
  30.         # this may be an array in a multi-processor system
  31.         Processor = $CIM_Processor.Name
  32.         ProcessorSpeed_Mhz = $CIM_Processor.MaxClockSpeed
  33.         InstalledRAM_GB = [math]::Round(($CIM_Ram.Capacity |
  34.             Measure-Object -Sum).Sum / 1GB, 2)
  35.         Manufacturer = $CIM_CS.Manufacturer
  36.         Model = $CIM_CS.Model
  37.         SerialNumber = $CIM_BE.SerialNumber
  38.         OS_Name = $CIM_OS.Caption
  39.         OS_Version = $CIM_OS.Version
  40.         OS_InstallDate = $CIM_OS.InstallDate.ToString('yyyy-MM-dd')
  41.         }
  42.     }
  43. $IC_Params = @{
  44.     ComputerName = $ComputerList
  45.     ScriptBlock = $IC_ScriptBlock
  46.     ErrorAction = 'SilentlyContinue'
  47.     }
  48. $RespondingSystems = Invoke-Command @IC_Params
  49.  
  50. $NOT_RespondingSystems = $ComputerList.Where({
  51.     # these two variants are needed to deal with an ipv6 localhost address
  52.     "[$_]" -notin $RespondingSystems.PSComputerName -and
  53.     $_ -notin $RespondingSystems.PSComputerName
  54.     }).
  55.     ForEach({
  56.         [PSCustomObject]@{
  57.             ComputerName = $_
  58.             ScanDate = [datetime]::Now.ToString('yyyy-MM-dd')
  59.             UserName = $NoResponse
  60.             Processor = $NoResponse
  61.             ProcessorSpeed_Mhz = $NoResponse
  62.             InstalledRAM_GB = $NoResponse
  63.             Manufacturer = $NoResponse
  64.             Model = $NoResponse
  65.             SerialNumber = $NoResponse
  66.             OS_Name = $NoResponse
  67.             OS_Version = $NoResponse
  68.             OS_InstallDate = $NoResponse
  69.             }
  70.         })
  71.  
  72. $RespondingSystems = $RespondingSystems |
  73.     Select-Object -Property * -ExcludeProperty PSComputerName, PSShowComputerName, RunspaceId
  74.  
  75. $AllSystems = $RespondingSystems + $NOT_RespondingSystems
  76.  
  77. # show on screen
  78. $AllSystems
  79.  
  80. # send to CSV
  81. $AllSystems |
  82.     Export-Csv -LiteralPath $FullReportFile -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement