Come creare un report HTML del proprio sistema con Powershell

Creare un report HTML del proprio sistema può sempre risultare molto utile, vediamo come fare.

Powershell: potenzialità quasi illimitate

Usando uno script di Powershell (redatto da Adam The Automator) è possibile ottenere un report in HTML molto intuitivo.

Per creare lo script procedere come segue:

Premere i pulsanti WIN + R e digitare notepad, ora incollare il seguente codice:

CSS codes
$header = @"
h1 { font-family: Arial, Helvetica, sans-serif; color: #e68a00; font-size: 28px; } h2 { font-family: Arial, Helvetica, sans-serif; color: #000099; font-size: 16px; } table { font-size: 12px; border: 0px; font-family: Arial, Helvetica, sans-serif; } td { padding: 4px; margin: 0px; border: 0; } th { background: #395870; background: linear-gradient(#49708f, #293f50); color: #fff; font-size: 11px; text-transform: uppercase; padding: 10px 15px; vertical-align: middle; } tbody tr:nth-child(even) { background: #f0f0f2; } #CreationDate { font-family: Arial, Helvetica, sans-serif; color: #ff3300; font-size: 12px; } .StopStatus { color: #ff0000; } .RunningStatus { color: #008000; }
"@
The command below will get the name of the computer
$ComputerName = "
Computer name: $env:computername
"
The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "
Operating System Information
"
The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "
Processor Information
"
The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "
BIOS Information
"
The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "
Disk Information
"
The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10 |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "
Services Information
"
$ServicesInfo = $ServicesInfo -replace 'Running','Running'
$ServicesInfo = $ServicesInfo -replace 'Stopped','Stopped'
The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Head $header -Title "Computer Information Report" -PostContent "
Creation Date: $(Get-Date)
"
The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html

Ora salvare il file come tipo Tutti i file ed assegnarli un nome, come ad esempio “Genera-Report-HTML.ps1” e dare OK.

Ora basterà avviare lo script in Powershell ed il report verrà creato in automatico nella cartella ove abbiamo salvato lo script.

Il report sarà simile a questo:

Nel report ci saranno informazioni riguardanti il sistema operativo, la CPU, versione del BIOS, informazioni sui dischi rigidi e sui servizi abilitati ed avviati.

Per comodità abbiamo creato lo script qui sotto:

Fonte: AdamTheAutomator

Articoli Correlati

Fine supporto a fine 2024 alle app Posta e Contatti

Addio di Paint 3D: fine supporto e ritiro dallo store [LINK PER IL DOWNLOAD]

Fine del supporto per Windows 10