Skip to content

Instantly share code, notes, and snippets.

@iyre
Last active September 23, 2022 19:31
Show Gist options
  • Save iyre/e8b6acf3cc8580c6df9287f7782a5a68 to your computer and use it in GitHub Desktop.
Save iyre/e8b6acf3cc8580c6df9287f7782a5a68 to your computer and use it in GitHub Desktop.
Queries system properties using WMI and exports findings to an HTML file
<#
.SYNOPSIS
Generates a report of system configuration
.DESCRIPTION
Queries system properties using WMI and exports findings to an HTML file
.PARAMETER ComputerName
Specifies target. Defaults to local hostname
.PARAMETER FilePath
Specifies output path. Defaults to current location
.PARAMETER Open
Open the generated report
.EXAMPLE
>.\New-HardwareReport.ps1
.EXAMPLE
>.\New-HardwareReport.ps1 localhost -FilePath C:\Temp -Open
#>
param (
[String]$ComputerName = $env:ComputerName,
[String]$FilePath = (Get-Location),
[Switch]$Open
)
$Title = "<H1>Device Summary : $ComputerName <SPAN style='font-size:.5em'></SPAN></H1>"
$Head = @'
<title>Device Summary</title>
<style>
*{font-family:calibri,arial;}
BODY{width=100%;margin:20px;}
TABLE{}
TABLE,TH,TD{border:1px solid black;border-collapse:collapse;text-align:left;}
TH,TD{padding:2px 5px;}
TH{background-color:thistle;}
</style>
'@
# System Info
$System = Get-WmiObject Win32_ComputerSystemProduct -ComputerName $ComputerName |
Select-Object Vendor, Version, Name |
ConvertTo-Html -As LIST -Fragment -PreContent "<H2 id='system'> System </H2>" |
Out-String
# BIOS
$Bios = Get-WmiObject Win32_Bios -ComputerName $ComputerName |
Select-Object Manufacturer, Name,
@{ Name='Version'; Expression={ $_.SMBIOSBIOSVersion } },
@{ Label='ReleaseDate'; Expression={ $_.ConvertToDateTime( $_.ReleaseDate ) } } |
ConvertTo-Html -As LIST -Fragment -PreContent "<H2 id='bios'> BIOS </H2>" |
Out-String
# MotherBoard
$Board = Get-WmiObject Win32_BaseBoard -ComputerName $ComputerName |
Select-Object Name, Manufacturer, Product |
ConvertTo-Html -As LIST -Fragment -PreContent "<H2 id='board'> MotherBoard </H2>" |
Out-String
# Processor
$Cpu = Get-WmiObject Win32_Processor -ComputerName $ComputerName |
Select-Object Name, Manufacturer, Caption,
@{ Name='ClockSpeed'; Expression={ $_.CurrentClockSpeed } }, DataWidth, L2CacheSize, L3CacheSize,
@{ Name='Cores'; Expression={ $_.NumberOfCores } },
@{ Name='Threads'; Expression={ $_.NumberOfLogicalProcessors } }, Status |
ConvertTo-Html -As LIST -Fragment -PreContent "<H2 id='cpu'> Processor </H2>" |
Out-String
# Memory
$Memory = Get-WmiObject Win32_PhysicalMemory -ComputerName $ComputerName |
Select-Object BankLabel, DeviceLocator, Capacity, Manufacturer, PartNumber, Speed |
ConvertTo-Html -Fragment -PreContent "<H2 id='memory'> Memory </H2>" |
Out-String
# Hard-Disk
$Disk = Get-WmiObject Win32_DiskDrive -ComputerName $ComputerName |
Select-Object Model, InterfaceType, Size, Partitions |
ConvertTo-Html -Fragment -PreContent "<H2 id='disk'> Disk </H2>" |
Out-String
# Network Adapters
$Network = Get-WmiObject Win32_NetworkAdapter -ComputerName $ComputerName |
Select-Object Name, Manufacturer, AdapterType, NetConnectionID |
Where-Object { $_.netconnectionid -like "*local area*" } |
ConvertTo-Html -Fragment -PreContent "<H2 id='network'> Network </H2>" |
Out-String
# PnP Devices
$Devices = Get-WmiObject Win32_PnpSignedDriver -ComputerName $ComputerName |
Select-Object DeviceName, HardwareID,
@{ Label='DriverDate'; Expression={ $_.ConvertToDateTime( $_.DriverDate ) } },
DriverProviderName, DriverVersion |
Where-Object { $_.HardwareID -ne $null -and $_.DriverDate -ne "6/21/2006" } |
ConvertTo-Html -Fragment -PreContent "<H2 id='devices'> Devices </H2>" |
Out-String
$FinalParams=@{
Head = $Head
PreContent = $Title
PostContent = $System, $Bios, $Board, $Cpu, $Memory, $Disk, $Network, $Devices
}
ConvertTo-Html @FinalParams > "$FilePath\$ComputerName.html"
if ( $Open ) {
Invoke-Expression "$FilePath\$ComputerName.html"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment