Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #requires -RunAsAdministrator
- # fake reading in a text file
- # in real life, use Get-Content
- $ComputerList = @'
- LocalHost
- 10.0.0.1
- 127.0.0.1
- BetterNotBeThere
- '@ -split [environment]::NewLine
- $TimeStamp = (Get-Date).ToString('yyyy-MM-dd_-_HH-mm-ss')
- $ReportPath = $env:TEMP
- $ReportFile = 'SystemReport_-_{0}.csv' -f $TimeStamp
- $FullReportFile = Join-Path -Path $ReportPath -ChildPath $ReportFile
- $NoResponse = '_n/a_'
- $IC_ScriptBlock = {
- $CIM_CS = Get-CimInstance -ClassName CIM_ComputerSystem
- $CIM_BE = Get-CimInstance -ClassName CIM_BIOSElement
- $CIM_Processor = Get-CimInstance -ClassName CIM_Processor
- $CIM_OS = Get-CimInstance -ClassName CIM_OperatingSystem
- $CIM_Ram = Get-CimInstance -ClassName CIM_PhysicalMemory
- [PSCustomObject]@{
- ComputerName = $CIM_CS.Name
- ScanDate = [datetime]::Now.ToString('yyyy-MM-dd')
- UserName = $CIM_CS.UserName
- # this may be an array in a multi-processor system
- Processor = $CIM_Processor.Name
- ProcessorSpeed_Mhz = $CIM_Processor.MaxClockSpeed
- InstalledRAM_GB = [math]::Round(($CIM_Ram.Capacity |
- Measure-Object -Sum).Sum / 1GB, 2)
- Manufacturer = $CIM_CS.Manufacturer
- Model = $CIM_CS.Model
- SerialNumber = $CIM_BE.SerialNumber
- OS_Name = $CIM_OS.Caption
- OS_Version = $CIM_OS.Version
- OS_InstallDate = $CIM_OS.InstallDate.ToString('yyyy-MM-dd')
- }
- }
- $IC_Params = @{
- ComputerName = $ComputerList
- ScriptBlock = $IC_ScriptBlock
- ErrorAction = 'SilentlyContinue'
- }
- $RespondingSystems = Invoke-Command @IC_Params
- $NOT_RespondingSystems = $ComputerList.Where({
- # these two variants are needed to deal with an ipv6 localhost address
- "[$_]" -notin $RespondingSystems.PSComputerName -and
- $_ -notin $RespondingSystems.PSComputerName
- }).
- ForEach({
- [PSCustomObject]@{
- ComputerName = $_
- ScanDate = [datetime]::Now.ToString('yyyy-MM-dd')
- UserName = $NoResponse
- Processor = $NoResponse
- ProcessorSpeed_Mhz = $NoResponse
- InstalledRAM_GB = $NoResponse
- Manufacturer = $NoResponse
- Model = $NoResponse
- SerialNumber = $NoResponse
- OS_Name = $NoResponse
- OS_Version = $NoResponse
- OS_InstallDate = $NoResponse
- }
- })
- $RespondingSystems = $RespondingSystems |
- Select-Object -Property * -ExcludeProperty PSComputerName, PSShowComputerName, RunspaceId
- $AllSystems = $RespondingSystems + $NOT_RespondingSystems
- # show on screen
- $AllSystems
- # send to CSV
- $AllSystems |
- Export-Csv -LiteralPath $FullReportFile -NoTypeInformation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement