774 lines
27 KiB
PowerShell
774 lines
27 KiB
PowerShell
#requires -Version 5.1
|
|
|
|
<#
|
|
WindowsMaintenanceReport.ps1
|
|
|
|
Three report levels:
|
|
|
|
Default Compact maintenance snapshot (target: under 20 lines)
|
|
-Mid Useful hardware/software/startup/driver inventory
|
|
-Full Everything, including networking, event logs, processes,
|
|
firewall, devices, DISM and SFC verification.
|
|
|
|
Examples:
|
|
|
|
.\WindowsMaintenanceReport.ps1
|
|
.\WindowsMaintenanceReport.ps1 -Mid
|
|
.\WindowsMaintenanceReport.ps1 -Full
|
|
.\WindowsMaintenanceReport.ps1 -Mid -OutputDirectory C:\Temp
|
|
.\WindowsMaintenanceReport.ps1 -Full -EventLogDays 30
|
|
|
|
Remote execution from a trusted URL:
|
|
|
|
irm 'https://example/WindowsMaintenanceReport.ps1' | iex
|
|
|
|
For flags when executing downloaded source:
|
|
|
|
$src = irm 'https://example/WindowsMaintenanceReport.ps1'
|
|
& ([ScriptBlock]::Create($src)) -Mid
|
|
|
|
Administrator privileges are recommended but not required.
|
|
The script is read-only. Admin-only checks are skipped when unavailable.
|
|
Output streams live to the terminal and is simultaneously saved to a report.
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[switch]$Mid,
|
|
[switch]$Full,
|
|
|
|
[string]$OutputDirectory = '',
|
|
|
|
[ValidateRange(1, 3650)]
|
|
[int]$EventLogDays = 7,
|
|
|
|
[ValidateRange(1, 5000)]
|
|
[int]$MaxEventErrors = 100
|
|
)
|
|
|
|
$ErrorActionPreference = 'Continue'
|
|
|
|
if ($Mid -and $Full) {
|
|
throw 'Choose either -Mid or -Full, not both.'
|
|
}
|
|
|
|
function Test-IsAdministrator {
|
|
try {
|
|
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
|
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
|
|
return $principal.IsInRole(
|
|
[Security.Principal.WindowsBuiltInRole]::Administrator
|
|
)
|
|
}
|
|
catch {
|
|
return $false
|
|
}
|
|
}
|
|
|
|
function Test-DirectoryWritable {
|
|
param([string]$Path)
|
|
|
|
try {
|
|
if (-not (Test-Path -LiteralPath $Path)) {
|
|
New-Item -ItemType Directory -Path $Path -Force -ErrorAction Stop | Out-Null
|
|
}
|
|
|
|
$testFile = Join-Path $Path (
|
|
'.winreport_write_test_' +
|
|
[guid]::NewGuid().ToString('N') +
|
|
'.tmp'
|
|
)
|
|
|
|
[System.IO.File]::WriteAllText($testFile, 'test')
|
|
Remove-Item -LiteralPath $testFile -Force -ErrorAction SilentlyContinue
|
|
return $true
|
|
}
|
|
catch {
|
|
return $false
|
|
}
|
|
}
|
|
|
|
function Write-Both {
|
|
param(
|
|
[System.IO.StreamWriter]$Writer,
|
|
[string]$Text = ''
|
|
)
|
|
|
|
Write-Host $Text
|
|
$Writer.WriteLine($Text)
|
|
$Writer.Flush()
|
|
}
|
|
|
|
function Write-Section {
|
|
param(
|
|
[System.IO.StreamWriter]$Writer,
|
|
[string]$Title,
|
|
[scriptblock]$Script
|
|
)
|
|
|
|
$separator = '=' * 80
|
|
|
|
Write-Both $Writer ''
|
|
Write-Both $Writer $separator
|
|
Write-Both $Writer $Title
|
|
Write-Both $Writer $separator
|
|
|
|
try {
|
|
$result = & $Script 2>&1
|
|
$text = $result | Out-String -Width 240
|
|
|
|
if ([string]::IsNullOrWhiteSpace($text)) {
|
|
Write-Both $Writer '(no output)'
|
|
}
|
|
else {
|
|
$lines = $text.TrimEnd() -split "`r?`n"
|
|
|
|
foreach ($line in $lines) {
|
|
Write-Both $Writer $line
|
|
}
|
|
}
|
|
}
|
|
catch {
|
|
Write-Both $Writer ('ERROR: ' + $_.Exception.Message)
|
|
}
|
|
}
|
|
function Get-InstalledPrograms {
|
|
$paths = @(
|
|
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
|
|
'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
|
|
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
|
|
)
|
|
|
|
Get-ItemProperty $paths -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.DisplayName } |
|
|
Select-Object DisplayName, DisplayVersion, Publisher,
|
|
InstallDate, InstallLocation |
|
|
Sort-Object DisplayName -Unique
|
|
}
|
|
|
|
function Get-StartupRegistryEntries {
|
|
$startupKeys = @(
|
|
'HKLM:\Software\Microsoft\Windows\CurrentVersion\Run',
|
|
'HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce',
|
|
'HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Run',
|
|
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Run',
|
|
'HKCU:\Software\Microsoft\Windows\CurrentVersion\RunOnce'
|
|
)
|
|
|
|
foreach ($key in $startupKeys) {
|
|
if (Test-Path $key) {
|
|
$item = Get-ItemProperty $key -ErrorAction SilentlyContinue
|
|
|
|
foreach ($property in $item.PSObject.Properties) {
|
|
if ($property.Name -notlike 'PS*') {
|
|
New-Object PSObject -Property @{
|
|
RegistryPath = $key
|
|
Name = $property.Name
|
|
Value = $property.Value
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function Get-ProblemDevices {
|
|
if (Get-Command Get-PnpDevice -ErrorAction SilentlyContinue) {
|
|
Get-PnpDevice -PresentOnly -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Status -ne 'OK' }
|
|
}
|
|
else {
|
|
Get-CimInstance Win32_PnPEntity -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.ConfigManagerErrorCode -ne 0 }
|
|
}
|
|
}
|
|
|
|
function Get-DiskHealthSummary {
|
|
if (-not (Get-Command Get-PhysicalDisk -ErrorAction SilentlyContinue)) {
|
|
return 'Unavailable'
|
|
}
|
|
|
|
try {
|
|
$physical = @(Get-PhysicalDisk -ErrorAction Stop)
|
|
|
|
if ($physical.Count -eq 0) {
|
|
return 'No physical disks returned'
|
|
}
|
|
|
|
$bad = @(
|
|
$physical |
|
|
Where-Object {
|
|
$_.HealthStatus -and
|
|
$_.HealthStatus -ne 'Healthy'
|
|
}
|
|
)
|
|
|
|
if ($bad.Count -eq 0) {
|
|
return 'Healthy (' + $physical.Count + ' disk(s))'
|
|
}
|
|
|
|
return (
|
|
($bad | ForEach-Object {
|
|
$_.FriendlyName + ': ' + $_.HealthStatus
|
|
}) -join '; '
|
|
)
|
|
}
|
|
catch {
|
|
return 'Unavailable'
|
|
}
|
|
}
|
|
|
|
$isAdmin = Test-IsAdministrator
|
|
|
|
if ([string]::IsNullOrWhiteSpace($OutputDirectory)) {
|
|
$candidate = (Get-Location).Path
|
|
|
|
if (Test-DirectoryWritable $candidate) {
|
|
$OutputDirectory = $candidate
|
|
}
|
|
elseif (Test-DirectoryWritable $env:TEMP) {
|
|
$OutputDirectory = $env:TEMP
|
|
}
|
|
else {
|
|
throw 'Could not find a writable output directory.'
|
|
}
|
|
}
|
|
elseif (-not (Test-DirectoryWritable $OutputDirectory)) {
|
|
throw "Output directory is not writable: $OutputDirectory"
|
|
}
|
|
|
|
$mode = 'Compact'
|
|
if ($Mid) { $mode = 'Mid' }
|
|
if ($Full) { $mode = 'Full' }
|
|
|
|
$timestamp = Get-Date -Format 'yyyyMMdd_HHmmss'
|
|
$computerName = $env:COMPUTERNAME
|
|
$reportName = 'windows_system_report_' + $computerName + '_' + $timestamp + '.txt'
|
|
$reportPath = Join-Path $OutputDirectory $reportName
|
|
|
|
$encoding = New-Object System.Text.UTF8Encoding($false)
|
|
$writer = New-Object System.IO.StreamWriter($reportPath, $false, $encoding)
|
|
|
|
try {
|
|
# ----------------------------------------------------------------------
|
|
# COMPACT DEFAULT
|
|
# ----------------------------------------------------------------------
|
|
if (-not $Mid -and -not $Full) {
|
|
$os = Get-CimInstance Win32_OperatingSystem
|
|
$system = Get-CimInstance Win32_ComputerSystem
|
|
$bios = Get-CimInstance Win32_BIOS
|
|
$cpu = Get-CimInstance Win32_Processor | Select-Object -First 1
|
|
$gpus = @(Get-CimInstance Win32_VideoController -ErrorAction SilentlyContinue)
|
|
$disks = @(Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3")
|
|
$programs = @(Get-InstalledPrograms)
|
|
$startupRegistry = @(Get-StartupRegistryEntries)
|
|
$startupCommands = @(Get-CimInstance Win32_StartupCommand -ErrorAction SilentlyContinue)
|
|
$autoServices = @(Get-CimInstance Win32_Service -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.StartMode -eq 'Auto' })
|
|
$stoppedAuto = @($autoServices | Where-Object { $_.State -ne 'Running' })
|
|
$problemDevices = @(Get-ProblemDevices)
|
|
$latestHotfix = Get-HotFix -ErrorAction SilentlyContinue |
|
|
Sort-Object InstalledOn -Descending |
|
|
Select-Object -First 1
|
|
|
|
$uptime = (Get-Date) - $os.LastBootUpTime
|
|
$ramTotalGB = [math]::Round($system.TotalPhysicalMemory / 1GB, 1)
|
|
$ramFreeGB = [math]::Round($os.FreePhysicalMemory / 1MB, 1)
|
|
|
|
$gpuText = if ($gpus.Count -gt 0) {
|
|
($gpus | ForEach-Object { $_.Name }) -join '; '
|
|
}
|
|
else {
|
|
'Unknown'
|
|
}
|
|
|
|
$diskText = if ($disks.Count -gt 0) {
|
|
($disks | ForEach-Object {
|
|
$size = [math]::Round($_.Size / 1GB, 0)
|
|
$free = [math]::Round($_.FreeSpace / 1GB, 0)
|
|
$pct = if ($_.Size) {
|
|
[math]::Round(($_.FreeSpace / $_.Size) * 100, 0)
|
|
}
|
|
else {
|
|
0
|
|
}
|
|
|
|
$_.DeviceID + ' ' + $free + '/' + $size + 'GB free (' + $pct + '%)'
|
|
}) -join '; '
|
|
}
|
|
else {
|
|
'Unknown'
|
|
}
|
|
|
|
$hotfixText = if ($latestHotfix) {
|
|
$date = if ($latestHotfix.InstalledOn) {
|
|
$latestHotfix.InstalledOn.ToString('yyyy-MM-dd')
|
|
}
|
|
else {
|
|
'date unknown'
|
|
}
|
|
$latestHotfix.HotFixID + ' (' + $date + ')'
|
|
}
|
|
else {
|
|
'Unavailable'
|
|
}
|
|
|
|
$defenderText = 'Unavailable'
|
|
if (Get-Command Get-MpComputerStatus -ErrorAction SilentlyContinue) {
|
|
try {
|
|
$def = Get-MpComputerStatus -ErrorAction Stop
|
|
$rt = if ($def.RealTimeProtectionEnabled) { 'ON' } else { 'OFF' }
|
|
$sig = if ($def.AntivirusSignatureLastUpdated) {
|
|
$def.AntivirusSignatureLastUpdated.ToString('yyyy-MM-dd HH:mm')
|
|
}
|
|
else {
|
|
'unknown'
|
|
}
|
|
$defenderText = 'Realtime ' + $rt + '; signatures ' + $sig
|
|
}
|
|
catch {
|
|
$defenderText = 'Unavailable'
|
|
}
|
|
}
|
|
|
|
$biosText = $bios.SMBIOSBIOSVersion
|
|
if ([string]::IsNullOrWhiteSpace($biosText)) {
|
|
$biosText = $bios.Name
|
|
}
|
|
|
|
Write-Both $writer 'WINDOWS MAINTENANCE SNAPSHOT'
|
|
Write-Both $writer ('Generated: ' + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss'))
|
|
Write-Both $writer ('Computer: ' + $computerName + ' | ' + $system.Manufacturer + ' ' + $system.Model)
|
|
Write-Both $writer ('OS: ' + $os.Caption + ' | ' + $os.Version + ' build ' + $os.BuildNumber + ' | ' + $os.OSArchitecture)
|
|
Write-Both $writer ('BIOS: ' + $biosText)
|
|
Write-Both $writer ('CPU: ' + $cpu.Name + ' | ' + $cpu.NumberOfCores + 'C/' + $cpu.NumberOfLogicalProcessors + 'T')
|
|
Write-Both $writer ('RAM: ' + $ramFreeGB + 'GB free / ' + $ramTotalGB + 'GB total')
|
|
Write-Both $writer ('GPU: ' + $gpuText)
|
|
Write-Both $writer ('Storage: ' + $diskText)
|
|
Write-Both $writer ('DiskHealth: ' + (Get-DiskHealthSummary))
|
|
Write-Both $writer ('Software: ' + $programs.Count + ' desktop programs; ' + (@(Get-AppxPackage -ErrorAction SilentlyContinue)).Count + ' AppX packages')
|
|
Write-Both $writer ('Startup: ' + $startupRegistry.Count + ' registry entries; ' + $startupCommands.Count + ' startup commands')
|
|
Write-Both $writer ('Services: ' + $autoServices.Count + ' automatic; ' + $stoppedAuto.Count + ' not running')
|
|
Write-Both $writer ('Devices: ' + $problemDevices.Count + ' reporting problems')
|
|
Write-Both $writer ('Update: ' + $hotfixText)
|
|
Write-Both $writer ('Defender: ' + $defenderText)
|
|
Write-Both $writer ('Uptime: ' + $uptime.Days + 'd ' + $uptime.Hours + 'h ' + $uptime.Minutes + 'm | Admin: ' + $isAdmin)
|
|
Write-Both $writer ('Report: ' + $reportPath)
|
|
|
|
return
|
|
}
|
|
|
|
# ----------------------------------------------------------------------
|
|
# MID + FULL COMMON SECTIONS
|
|
# ----------------------------------------------------------------------
|
|
Write-Both $writer 'WINDOWS SYSTEM / MAINTENANCE REPORT'
|
|
Write-Both $writer ('Mode: ' + $mode)
|
|
Write-Both $writer ('Generated: ' + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss K'))
|
|
Write-Both $writer ('Computer: ' + $computerName)
|
|
Write-Both $writer ('User: ' + $env:USERNAME)
|
|
Write-Both $writer ('Administrator: ' + $isAdmin)
|
|
Write-Both $writer ('PowerShell: ' + $PSVersionTable.PSVersion)
|
|
Write-Both $writer ('Report: ' + $reportPath)
|
|
|
|
if (-not $isAdmin) {
|
|
Write-Both $writer ''
|
|
Write-Both $writer 'NOTE: Script is not elevated. Admin-only diagnostics will be skipped.'
|
|
}
|
|
|
|
Write-Section $writer 'OPERATING SYSTEM / COMPUTER / BIOS' {
|
|
Get-CimInstance Win32_OperatingSystem |
|
|
Select-Object Caption, Version, BuildNumber, OSArchitecture,
|
|
InstallDate, LastBootUpTime, LocalDateTime,
|
|
@{Name='TotalMemoryGB';Expression={[math]::Round($_.TotalVisibleMemorySize / 1MB, 2)}},
|
|
@{Name='FreeMemoryGB';Expression={[math]::Round($_.FreePhysicalMemory / 1MB, 2)}} |
|
|
Format-List
|
|
|
|
Get-CimInstance Win32_ComputerSystem |
|
|
Select-Object Manufacturer, Model, SystemType,
|
|
@{Name='TotalPhysicalMemoryGB';Expression={[math]::Round($_.TotalPhysicalMemory / 1GB, 2)}},
|
|
Domain, PartOfDomain |
|
|
Format-List
|
|
|
|
Get-CimInstance Win32_BIOS |
|
|
Select-Object Manufacturer, Name, SMBIOSBIOSVersion,
|
|
ReleaseDate, SerialNumber |
|
|
Format-List
|
|
}
|
|
|
|
Write-Section $writer 'CPU' {
|
|
Get-CimInstance Win32_Processor |
|
|
Select-Object Name, Manufacturer, NumberOfCores,
|
|
NumberOfLogicalProcessors, MaxClockSpeed,
|
|
CurrentClockSpeed, LoadPercentage |
|
|
Format-List
|
|
}
|
|
|
|
Write-Section $writer 'MEMORY MODULES' {
|
|
Get-CimInstance Win32_PhysicalMemory |
|
|
Select-Object BankLabel, DeviceLocator,
|
|
@{Name='CapacityGB';Expression={[math]::Round($_.Capacity / 1GB, 2)}},
|
|
Speed, ConfiguredClockSpeed, Manufacturer, PartNumber |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'MOTHERBOARD' {
|
|
Get-CimInstance Win32_BaseBoard |
|
|
Select-Object Manufacturer, Product, Version, SerialNumber |
|
|
Format-List
|
|
}
|
|
|
|
Write-Section $writer 'GPU / DISPLAY ADAPTERS' {
|
|
Get-CimInstance Win32_VideoController |
|
|
Select-Object Name, DriverVersion, VideoModeDescription |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'STORAGE / FREE SPACE / HEALTH' {
|
|
'Logical volumes:'
|
|
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
|
|
Select-Object DeviceID, VolumeName, FileSystem,
|
|
@{Name='SizeGB';Expression={[math]::Round($_.Size / 1GB, 2)}},
|
|
@{Name='FreeGB';Expression={[math]::Round($_.FreeSpace / 1GB, 2)}},
|
|
@{Name='FreePercent';Expression={
|
|
if ($_.Size) {
|
|
[math]::Round(($_.FreeSpace / $_.Size) * 100, 1)
|
|
}
|
|
}} |
|
|
Format-Table -AutoSize
|
|
|
|
''
|
|
'Physical disks:'
|
|
Get-CimInstance Win32_DiskDrive |
|
|
Select-Object Model, InterfaceType, MediaType,
|
|
@{Name='SizeGB';Expression={[math]::Round($_.Size / 1GB, 2)}},
|
|
FirmwareRevision, SerialNumber, Status |
|
|
Format-Table -AutoSize
|
|
|
|
''
|
|
'Storage health:'
|
|
if (Get-Command Get-PhysicalDisk -ErrorAction SilentlyContinue) {
|
|
try {
|
|
Get-PhysicalDisk -ErrorAction Stop |
|
|
Select-Object FriendlyName, MediaType, HealthStatus,
|
|
OperationalStatus,
|
|
@{Name='SizeGB';Expression={[math]::Round($_.Size / 1GB, 2)}} |
|
|
Format-Table -AutoSize
|
|
|
|
if ($isAdmin) {
|
|
Get-PhysicalDisk | ForEach-Object {
|
|
''
|
|
'Reliability: ' + $_.FriendlyName
|
|
try {
|
|
$_ | Get-StorageReliabilityCounter -ErrorAction Stop |
|
|
Select-Object Temperature, Wear,
|
|
ReadErrorsTotal, WriteErrorsTotal,
|
|
PowerOnHours |
|
|
Format-List
|
|
}
|
|
catch {
|
|
'Reliability counters unavailable: ' + $_.Exception.Message
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
'Detailed reliability counters skipped: not elevated.'
|
|
}
|
|
}
|
|
catch {
|
|
'Storage health unavailable: ' + $_.Exception.Message
|
|
}
|
|
}
|
|
else {
|
|
'Get-PhysicalDisk is unavailable on this system.'
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'INSTALLED PROGRAMS' {
|
|
Get-InstalledPrograms |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'MICROSOFT STORE / APPX PACKAGES' {
|
|
if (Get-Command Get-AppxPackage -ErrorAction SilentlyContinue) {
|
|
Get-AppxPackage -ErrorAction SilentlyContinue |
|
|
Select-Object Name, Version, Publisher, Architecture |
|
|
Sort-Object Name |
|
|
Format-Table -AutoSize
|
|
}
|
|
else {
|
|
'Get-AppxPackage is unavailable.'
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'STARTUP REGISTRY LOCATIONS' {
|
|
$entries = @(Get-StartupRegistryEntries)
|
|
|
|
if ($entries.Count -eq 0) {
|
|
'(no startup registry entries found)'
|
|
}
|
|
else {
|
|
$entries |
|
|
Sort-Object RegistryPath, Name |
|
|
Format-Table RegistryPath, Name, Value -Wrap -AutoSize
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'AUTOMATIC SERVICES' {
|
|
Get-CimInstance Win32_Service |
|
|
Where-Object { $_.StartMode -eq 'Auto' } |
|
|
Select-Object Name, DisplayName, State, StartMode, StartName |
|
|
Sort-Object State, DisplayName |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'SIGNED DRIVERS' {
|
|
Get-CimInstance Win32_PnPSignedDriver |
|
|
Where-Object { $_.DeviceName } |
|
|
Select-Object DeviceName, Manufacturer, DriverVersion, DriverDate |
|
|
Sort-Object DeviceName |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'WINDOWS UPDATES / HOTFIXES' {
|
|
Get-HotFix -ErrorAction SilentlyContinue |
|
|
Sort-Object InstalledOn -Descending |
|
|
Select-Object HotFixID, Description, InstalledBy, InstalledOn |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'WINDOWS DEFENDER STATUS' {
|
|
if (Get-Command Get-MpComputerStatus -ErrorAction SilentlyContinue) {
|
|
try {
|
|
Get-MpComputerStatus -ErrorAction Stop |
|
|
Select-Object AntivirusEnabled, AntispywareEnabled,
|
|
RealTimeProtectionEnabled, BehaviorMonitorEnabled,
|
|
IoavProtectionEnabled, NISEnabled,
|
|
AntivirusSignatureLastUpdated,
|
|
AntispywareSignatureLastUpdated,
|
|
QuickScanAge, FullScanAge |
|
|
Format-List
|
|
}
|
|
catch {
|
|
'Defender status unavailable: ' + $_.Exception.Message
|
|
}
|
|
}
|
|
else {
|
|
'Microsoft Defender cmdlets unavailable.'
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'NON-MICROSOFT SCHEDULED TASKS' {
|
|
if (Get-Command Get-ScheduledTask -ErrorAction SilentlyContinue) {
|
|
Get-ScheduledTask -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.TaskPath -notlike '\Microsoft\*' } |
|
|
Select-Object TaskName, TaskPath, State |
|
|
Sort-Object TaskPath, TaskName |
|
|
Format-Table -AutoSize
|
|
}
|
|
}
|
|
|
|
# ----------------------------------------------------------------------
|
|
# FULL-ONLY SECTIONS
|
|
# ----------------------------------------------------------------------
|
|
if ($Full) {
|
|
Write-Section $writer 'UPTIME' {
|
|
$os = Get-CimInstance Win32_OperatingSystem
|
|
$uptime = (Get-Date) - $os.LastBootUpTime
|
|
|
|
New-Object PSObject -Property @{
|
|
LastBoot = $os.LastBootUpTime
|
|
Days = $uptime.Days
|
|
Hours = $uptime.Hours
|
|
Minutes = $uptime.Minutes
|
|
} | Format-List
|
|
}
|
|
|
|
Write-Section $writer 'STARTUP PROGRAMS' {
|
|
Get-CimInstance Win32_StartupCommand |
|
|
Select-Object Name, Command, Location, User |
|
|
Sort-Object Name |
|
|
Format-Table -Wrap -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'STARTUP FOLDERS' {
|
|
$folders = @(
|
|
(Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs\Startup'),
|
|
(Join-Path $env:ProgramData 'Microsoft\Windows\Start Menu\Programs\Startup')
|
|
)
|
|
|
|
foreach ($folder in $folders) {
|
|
''
|
|
'Folder: ' + $folder
|
|
|
|
if (Test-Path $folder) {
|
|
Get-ChildItem $folder -Force -ErrorAction SilentlyContinue |
|
|
Select-Object Name, FullName, LastWriteTime |
|
|
Format-Table -AutoSize
|
|
}
|
|
else {
|
|
'(not present)'
|
|
}
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'AUTOMATIC SERVICES NOT RUNNING' {
|
|
Get-CimInstance Win32_Service |
|
|
Where-Object {
|
|
$_.StartMode -eq 'Auto' -and $_.State -ne 'Running'
|
|
} |
|
|
Select-Object Name, DisplayName, State, StartMode |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer 'DEVICES WITH PROBLEMS' {
|
|
$devices = @(Get-ProblemDevices)
|
|
|
|
if ($devices.Count -eq 0) {
|
|
'(no problem devices found)'
|
|
}
|
|
else {
|
|
$devices |
|
|
Select-Object Status, Class, FriendlyName, InstanceId,
|
|
Name, PNPClass, ConfigManagerErrorCode, DeviceID |
|
|
Format-Table -Wrap -AutoSize
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'FIREWALL PROFILES' {
|
|
if (Get-Command Get-NetFirewallProfile -ErrorAction SilentlyContinue) {
|
|
Get-NetFirewallProfile -ErrorAction SilentlyContinue |
|
|
Select-Object Name, Enabled, DefaultInboundAction,
|
|
DefaultOutboundAction |
|
|
Format-Table -AutoSize
|
|
}
|
|
else {
|
|
'Get-NetFirewallProfile is unavailable.'
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'NETWORK ADAPTERS' {
|
|
if (Get-Command Get-NetAdapter -ErrorAction SilentlyContinue) {
|
|
Get-NetAdapter -ErrorAction SilentlyContinue |
|
|
Select-Object Name, InterfaceDescription, Status,
|
|
LinkSpeed, MacAddress |
|
|
Format-Table -AutoSize
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'IP CONFIGURATION' {
|
|
ipconfig /all
|
|
}
|
|
|
|
Write-Section $writer 'DNS SERVERS' {
|
|
if (Get-Command Get-DnsClientServerAddress -ErrorAction SilentlyContinue) {
|
|
Get-DnsClientServerAddress -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.ServerAddresses.Count -gt 0 } |
|
|
Select-Object InterfaceAlias, AddressFamily,
|
|
@{Name='Servers';Expression={$_.ServerAddresses -join ', '}} |
|
|
Format-Table -AutoSize
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'ACTIVE TCP LISTENERS' {
|
|
if (Get-Command Get-NetTCPConnection -ErrorAction SilentlyContinue) {
|
|
Get-NetTCPConnection -State Listen -ErrorAction SilentlyContinue |
|
|
Select-Object LocalAddress, LocalPort, OwningProcess |
|
|
Sort-Object LocalPort |
|
|
Format-Table -AutoSize
|
|
}
|
|
else {
|
|
netstat -ano
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'POWER PLAN' {
|
|
powercfg /getactivescheme
|
|
}
|
|
|
|
Write-Section $writer 'BATTERY' {
|
|
Get-CimInstance Win32_Battery -ErrorAction SilentlyContinue |
|
|
Select-Object Name, Status, EstimatedChargeRemaining,
|
|
EstimatedRunTime, BatteryStatus |
|
|
Format-List
|
|
}
|
|
|
|
Write-Section $writer 'TOP PROCESSES BY MEMORY' {
|
|
Get-Process |
|
|
Sort-Object WorkingSet64 -Descending |
|
|
Select-Object -First 30 ProcessName, Id,
|
|
@{Name='MemoryMB';Expression={[math]::Round($_.WorkingSet64 / 1MB, 1)}},
|
|
CPU |
|
|
Format-Table -AutoSize
|
|
}
|
|
|
|
Write-Section $writer ('RECENT SYSTEM ERRORS - LAST ' + $EventLogDays + ' DAYS') {
|
|
$start = (Get-Date).AddDays(-$EventLogDays)
|
|
|
|
Get-WinEvent -FilterHashtable @{
|
|
LogName = 'System'
|
|
Level = 2
|
|
StartTime = $start
|
|
} -ErrorAction SilentlyContinue |
|
|
Select-Object -First $MaxEventErrors TimeCreated, Id,
|
|
ProviderName, Message |
|
|
Format-List
|
|
}
|
|
|
|
Write-Section $writer ('RECENT APPLICATION ERRORS - LAST ' + $EventLogDays + ' DAYS') {
|
|
$start = (Get-Date).AddDays(-$EventLogDays)
|
|
|
|
Get-WinEvent -FilterHashtable @{
|
|
LogName = 'Application'
|
|
Level = 2
|
|
StartTime = $start
|
|
} -ErrorAction SilentlyContinue |
|
|
Select-Object -First $MaxEventErrors TimeCreated, Id,
|
|
ProviderName, Message |
|
|
Format-List
|
|
}
|
|
|
|
Write-Section $writer 'WINDOWS COMPONENT STORE STATUS' {
|
|
if ($isAdmin) {
|
|
'[RUNNING] DISM.exe /Online /Cleanup-Image /CheckHealth'
|
|
DISM.exe /Online /Cleanup-Image /CheckHealth
|
|
}
|
|
else {
|
|
'Skipped: DISM /CheckHealth requires an elevated session.'
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'SYSTEM FILE CHECK - VERIFY ONLY' {
|
|
if ($isAdmin) {
|
|
'[RUNNING] sfc.exe /verifyonly'
|
|
sfc.exe /verifyonly
|
|
}
|
|
else {
|
|
'Skipped: sfc /verifyonly requires an elevated session.'
|
|
}
|
|
}
|
|
|
|
Write-Section $writer 'IMPORTANT DIRECTORIES' {
|
|
$programFilesX86 = [Environment]::GetEnvironmentVariable('ProgramFiles(x86)')
|
|
|
|
New-Object PSObject -Property @{
|
|
WindowsDirectory = $env:WINDIR
|
|
SystemDrive = $env:SystemDrive
|
|
ProgramFiles = $env:ProgramFiles
|
|
ProgramFilesX86 = $programFilesX86
|
|
ProgramData = $env:ProgramData
|
|
UserProfile = $env:USERPROFILE
|
|
Temp = $env:TEMP
|
|
} | Format-List
|
|
}
|
|
}
|
|
|
|
Write-Both $writer ''
|
|
Write-Both $writer ('Completed: ' + (Get-Date -Format 'yyyy-MM-dd HH:mm:ss K'))
|
|
Write-Both $writer ('Saved to: ' + $reportPath)
|
|
}
|
|
finally {
|
|
if ($writer) {
|
|
$writer.Dispose()
|
|
}
|
|
}
|