Get System Information
# VARIABLES
$GetDate = Get-Date -Format ddMMyyyy_HHmmss
$GetHostname = (Get-CimInstance -ClassName Win32_ComputerSystem).Name
$HostnameDate = "$GetHostname" + "_" + "$GetDate"
# DEFINE OUTPUT FILE PATHS
$csvPathSystem = "$HostnameDate\Server_SystemInfo.csv"
$csvPathDisk = "$HostnameDate\Server_DiskInfo.csv"
$csvPathSoftware = "$HostnameDate\Server_InstalledSoftware.csv"
$csvPathPatches = "$HostnameDate\Server_InstalledPatches.csv"
$csvPathNetwork = "$HostnameDate\Server_NetworkInfo.csv"
$csvPathDomain = "$HostnameDate\Server_DomainInfo.csv"
$csvPathIPConfig = "$HostnameDate\Server_IPConfig.csv"
$htmlPath = "$HostnameDate\ServerReport.html"
# CREATE FOLDER
New-Item -Path ".\" -Name "$HostnameDate" -ItemType "directory" | Out-Null
# COLLECT SYSTEM INFORMATION
$SystemInfo = [PSCustomObject]@{
ServerName = $env:COMPUTERNAME
OSName = (Get-ComputerInfo).OsName
OSVersion = (Get-ComputerInfo).OsArchitecture
LastBootTime = (Get-CimInstance Win32_OperatingSystem).LastBootUpTime
SystemUpTime = ((Get-Date) - (Get-CimInstance Win32_OperatingSystem).LastBootUpTime).Days
InstallDate = (Get-CimInstance Win32_OperatingSystem).InstallDate
Manufacturer = (Get-ComputerInfo).CsManufacturer
Model = (Get-ComputerInfo).CsModel
Processor = (Get-ComputerInfo).CsProcessors
TotalRAMGB = [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 2)
}
$SystemInfo | Export-Csv -Path $csvPathSystem -NoTypeInformation
# COLLECT DISK INFORMATION
$DiskInfo = Get-PSDrive | Where-Object { $_.Provider -like "Microsoft.PowerShell.Core\FileSystem" } | Select-Object Name, @{n = "TotalSizeGB"; e = { [math]::Round(($_.Used + $_.Free) / 1GB, 2) } }, @{n = "FreeSpaceGB"; e = { [math]::Round($_.Free / 1GB, 2) } }
$DiskInfo | Export-Csv -Path $csvPathDisk -NoTypeInformation
# GET INSTALLED SOFTWARE FROM REGISTRY (MORE ACCURATE)
$RegistryPaths = @(
"HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
)
$InstalledSoftware = @()
foreach ($path in $RegistryPaths) {
if (Test-Path $path) {
# ENSURE THE REGISTRY PATH EXISTS BEFORE QUERYING
$InstalledSoftware += Get-ItemProperty -Path $path | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
}
}
# FILTER OUT EMPTY DISPLAYNAME VALUES
$InstalledSoftware = $InstalledSoftware | Where-Object { $_.DisplayName -ne $null }
$InstalledSoftware | Export-Csv -Path $csvPathSoftware -NoTypeInformation
# COLLECT INSTALLED WINDOWS UPDATES
$InstalledPatches = Get-HotFix | Select-Object HotFixID, Description, InstalledOn
$InstalledPatches | Export-Csv -Path $csvPathPatches -NoTypeInformation
# COLLECT NETWORK DETAILS
$NetworkInfo = Get-NetIPAddress | Where-Object { $_.AddressFamily -eq "IPv4" } | Select-Object InterfaceAlias, IPAddress
$NetworkInfo | Export-Csv -Path $csvPathNetwork -NoTypeInformation
# GET DOMAIN INFORMATION
$DomainInfo = [PSCustomObject]@{
DomainName = (Get-WmiObject Win32_ComputerSystem).Domain
DomainRole = (Get-WmiObject Win32_ComputerSystem).DomainRole
DNSHostName = (Get-WmiObject Win32_ComputerSystem).DNSHostName
}
$DomainInfo | Export-Csv -Path $csvPathDomain -NoTypeInformation
# GET FULL IP CONFIGURATION (FIXED VERSION)
$IPConfig = Get-NetIPConfiguration | Format-List | Out-String
$IPConfig | Out-File -FilePath $csvPathIPConfig
# CONVERT TO HTML
$HtmlReport = "<html><body><h2>Server Information Report</h2>"
$HtmlReport += "<h3>System Information</h3><pre>" + ($SystemInfo | Out-String) + "</pre>"
$HtmlReport += "<h3>Disk Information</h3><pre>" + ($DiskInfo | Out-String) + "</pre>"
$HtmlReport += "<h3>Installed Software</h3><pre>" + ($InstalledSoftware | Out-String) + "</pre>"
$HtmlReport += "<h3>Installed Patches</h3><pre>" + ($InstalledPatches | Out-String) + "</pre>"
$HtmlReport += "<h3>Network Information</h3><pre>" + ($NetworkInfo | Out-String) + "</pre>"
$HtmlReport += "<h3>Domain Information</h3><pre>" + ($DomainInfo | Out-String) + "</pre>"
$HtmlReport += "<h3>IP Configuration</h3><pre>" + $IPConfig + "</pre>"
$HtmlReport += "</body></html>"
$HtmlReport | Out-File -FilePath $htmlPath
Write-Host "Server report generated:"
Write-Host "CSV Reports:"
Write-Host " - System Info: $csvPathSystem"
Write-Host " - Disk Info: $csvPathDisk"
Write-Host " - Installed Software: $csvPathSoftware"
Write-Host " - Installed Patches: $csvPathPatches"
Write-Host " - Network Info: $csvPathNetwork"
Write-Host " - Domain Info: $csvPathDomain"
Write-Host " - IPConfig Output: $csvPathIPConfig"
Write-Host "HTML Report: $htmlPath"