PoshCode Archive  Artifact [8dad441194]

Artifact 8dad441194c235729a1c5863230e8cea4880e21c157c6412d059895b7db8182a:

  • File HTML-Hardware-Reports-wi.ps1 — part of check-in [32b16d227b] at 2018-06-10 13:36:48 on branch trunk — Author: Ranger6 aka Bitspider on Twitter (user: Ranger69 size: 4775)

# encoding: utf-8
# api: powershell
# title: HTML Hardware Reports wi
# description: Author: Ranger6 aka Bitspider on Twitter
# version: 0.1
# type: function
# author: Ranger69
# license: CC0
# function: Get-HardwareReport
# x-poshcode-id: 4114
# x-archived: 2013-04-24T08:13:56
# x-published: 2013-04-18T05:41:00
#
# Link: insidepowershell.com
# Post date: April 16, 2013
# This function determines if the device is online before proceeding to gather hardware information and creating a report in HTML format. Remember, if this works for you, then leverage the function by including it your PowerShell profile.
# You can call this function in two distinct ways. First, you can have strings piped into it — such as from a text file that contains one server or computer names per line. Depending on what your calling, you may have to play around with the wmi classes used and the select statements that follow.
# Pipe lining Strings into the Function:
# Get-Content $home\devices.txt | Get-HardwareReport
# You can also have one or more computer names passed directly to the parameter, without using the pipeline at all:
# Get-HardwareReport –devices SERVER1,SERVER2
#
Function Get-HardwareReport {
[CmdletBinding()] Param
(
[parameter(Mandatory=$true,
ValueFromPipeline=$true)] [String[]]$devices
)
Begin {Write-Host " Starting Hardware Reports"}
Process {
foreach ($device in $devices) {
$name=$device
$filepath="$home\$name.html"
$PingDevice=Test-Connection $name -count 1 -quiet;trap{continue}
#Ping Test, then Server is online so get the hardware info
If ($PingDevice -eq “True”) {
Write-Host " Processing info for $name "
#### HTML Output Formatting #######
$a = "<style>"
$a = $a + "BODY{background-color:Lavender ;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:skyblue}"
$a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:lightyellow}"
$a = $a + "</style><Title>$name Hardware Report</Title>"
####################################
ConvertTo-Html -Head $a -Body "<h1> Computer Name : $name </h1>" > "$filepath"
# MotherBoard: Win32_BaseBoard # You can Also select Tag,Weight,Width
Get-WmiObject -ComputerName $name Win32_BaseBoard | Select Name,Manufacturer,Product,SerialNumber,Status | ConvertTo-html -Body "<H2> MotherBoard Information</H2>" >> "$filepath"
# BIOS
Get-WmiObject win32_bios -ComputerName $name | Select Manufacturer,Name,@{name='biosversion' ; Expression={$_.biosversion -join '; '}}, @{name='ListOfLanguages' ; Expression={$_.ListOfLanguages -join '; '}},PrimaryBIOS,ReleaseDate,SMBIOSBIOSVersion,SMBIOSMajorVersion,SMBIOSMinorVersion | ConvertTo-html -Body "<H2> BIOS Information </H2>" >>"$filepath"
# CD ROM Drive
Get-WmiObject Win32_CDROMDrive -ComputerName $name | select Name,Drive,MediaLoaded,MediaType,MfrAssignedRevisionLevel | ConvertTo-html -Body "<H2> CD ROM Information</H2>" >> "$filepath"
# System Info
Get-WmiObject Win32_ComputerSystemProduct -ComputerName $name | Select Vendor,Version,Name,IdentifyingNumber,UUID | ConvertTo-html -Body "<H2> System Information </H2>" >> "$filepath"
# Hard-Disk
Get-WmiObject win32_diskDrive -ComputerName $name | select Model,SerialNumber,InterfaceType,Size,Partitions | ConvertTo-html -Body "<H2> Harddisk Information </H2>" >> "$filepath"
# NetWord Adapters -ComputerName $name
Get-WmiObject win32_networkadapter -ComputerName $name | Select Name,Manufacturer,Description ,AdapterType,Speed,MACAddress,NetConnectionID | ConvertTo-html -Body "<H2> Network Card Information</H2>" >> "$filepath"
# Memory
Get-WmiObject Win32_PhysicalMemory -ComputerName $name | select BankLabel,DeviceLocator,Capacity,Manufacturer,PartNumber,SerialNumber,Speed | ConvertTo-html -Body "<H2> Physical Memory Information</H2>" >> "$filepath"
# Processor
Get-WmiObject Win32_Processor -ComputerName $name | Select Name,Manufacturer,Caption,DeviceID,CurrentClockSpeed,CurrentVoltage,DataWidth,L2CacheSize,L3CacheSize,NumberOfCores,NumberOfLogicalProcessors,Status | ConvertTo-html -Body "<H2> CPU Information</H2>" >> "$filepath"
## System enclosure
Get-WmiObject Win32_SystemEnclosure -ComputerName $name | Select Tag,InstallDate,LockPresent,PartNumber,SerialNumber | ConvertTo-html -Body "<H2> System Enclosure Information </H2>" >> "$filepath"
## Invoke Expressons
invoke-Expression "$filepath"
# Closing If Statement
}else {Write-Host " $name is offline - will not be included in the reports"}
#Closing For Loop
}
# Closing Process
}
End {Write-Host "Ending Hardware Report for $name"}
#Closing Function Get-HardwareReport
}