Delete main.py
This commit is contained in:
parent
83b624d2aa
commit
1cb81f79db
538
main.py
538
main.py
|
|
@ -1,538 +0,0 @@
|
|||
import subprocess
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
import socket
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
REPORT = Path(
|
||||
f"windows_system_report_{datetime.now().strftime('%Y%m%d_%H%M%S')}.txt"
|
||||
)
|
||||
|
||||
def run(cmd, shell=True, timeout=60):
|
||||
try:
|
||||
p = subprocess.run(
|
||||
cmd,
|
||||
shell=shell,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
timeout=timeout,
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
output = p.stdout.strip()
|
||||
|
||||
if p.stderr.strip():
|
||||
output += "\n\n[stderr]\n" + p.stderr.strip()
|
||||
|
||||
return output or "(no output)"
|
||||
except subprocess.TimeoutExpired:
|
||||
return "(command timed out)"
|
||||
except Exception as e:
|
||||
return f"(error: {e})"
|
||||
|
||||
|
||||
def powershell(command, timeout=90):
|
||||
return run(
|
||||
[
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-ExecutionPolicy",
|
||||
"Bypass",
|
||||
"-Command",
|
||||
command,
|
||||
],
|
||||
shell=False,
|
||||
timeout=timeout,
|
||||
)
|
||||
|
||||
|
||||
def section(f, title, content):
|
||||
f.write("\n")
|
||||
f.write("=" * 80 + "\n")
|
||||
f.write(title + "\n")
|
||||
f.write("=" * 80 + "\n")
|
||||
f.write(str(content).rstrip() + "\n")
|
||||
|
||||
|
||||
with REPORT.open("w", encoding="utf-8") as f:
|
||||
f.write("WINDOWS SYSTEM / MAINTENANCE REPORT\n")
|
||||
f.write(f"Generated: {datetime.now()}\n")
|
||||
f.write(f"Computer: {socket.gethostname()}\n")
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Basic system information
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"BASIC SYSTEM INFORMATION",
|
||||
f"""
|
||||
Computer name : {socket.gethostname()}
|
||||
Python : {sys.version}
|
||||
OS : {platform.platform()}
|
||||
Release : {platform.release()}
|
||||
Version : {platform.version()}
|
||||
Architecture : {platform.machine()}
|
||||
Processor : {platform.processor()}
|
||||
Username : {os.environ.get('USERNAME', 'Unknown')}
|
||||
""",
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"WINDOWS / BIOS / COMPUTER SYSTEM",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_OperatingSystem |
|
||||
Select-Object Caption,Version,BuildNumber,OSArchitecture,
|
||||
InstallDate,LastBootUpTime,LocalDateTime,
|
||||
TotalVisibleMemorySize,FreePhysicalMemory |
|
||||
Format-List
|
||||
|
||||
Get-CimInstance Win32_ComputerSystem |
|
||||
Select-Object Manufacturer,Model,SystemType,
|
||||
TotalPhysicalMemory,Domain,PartOfDomain |
|
||||
Format-List
|
||||
|
||||
Get-CimInstance Win32_BIOS |
|
||||
Select-Object Manufacturer,Name,SMBIOSBIOSVersion,
|
||||
ReleaseDate,SerialNumber |
|
||||
Format-List
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Hardware
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"CPU",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_Processor |
|
||||
Select-Object Name,Manufacturer,NumberOfCores,
|
||||
NumberOfLogicalProcessors,MaxClockSpeed,
|
||||
CurrentClockSpeed,LoadPercentage |
|
||||
Format-List
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"MEMORY MODULES",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_PhysicalMemory |
|
||||
Select-Object BankLabel,DeviceLocator,
|
||||
@{N='CapacityGB';E={[math]::Round($_.Capacity/1GB,2)}},
|
||||
Speed,ConfiguredClockSpeed,Manufacturer,PartNumber |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"GPU / DISPLAY ADAPTERS",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_VideoController |
|
||||
Select-Object Name,DriverVersion,
|
||||
@{N='VRAM_GB';E={[math]::Round($_.AdapterRAM/1GB,2)}},
|
||||
VideoModeDescription |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"MOTHERBOARD",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_BaseBoard |
|
||||
Select-Object Manufacturer,Product,Version,SerialNumber |
|
||||
Format-List
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Storage
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"LOGICAL DISKS / FREE SPACE",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
|
||||
Select-Object DeviceID,VolumeName,FileSystem,
|
||||
@{N='SizeGB';E={[math]::Round($_.Size/1GB,2)}},
|
||||
@{N='FreeGB';E={[math]::Round($_.FreeSpace/1GB,2)}},
|
||||
@{N='FreePercent';E={
|
||||
if ($_.Size) {
|
||||
[math]::Round(($_.FreeSpace/$_.Size)*100,1)
|
||||
}
|
||||
}} |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"PHYSICAL DISKS",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_DiskDrive |
|
||||
Select-Object Model,InterfaceType,MediaType,
|
||||
@{N='SizeGB';E={[math]::Round($_.Size/1GB,2)}},
|
||||
FirmwareRevision,SerialNumber,Status |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"STORAGE RELIABILITY / HEALTH",
|
||||
powershell(r"""
|
||||
if (Get-Command Get-PhysicalDisk -ErrorAction SilentlyContinue) {
|
||||
Get-PhysicalDisk |
|
||||
Select-Object FriendlyName,MediaType,HealthStatus,
|
||||
OperationalStatus,Size |
|
||||
Format-Table -AutoSize
|
||||
|
||||
Get-PhysicalDisk | ForEach-Object {
|
||||
Write-Output ""
|
||||
Write-Output ("Disk: " + $_.FriendlyName)
|
||||
|
||||
try {
|
||||
$_ | Get-StorageReliabilityCounter |
|
||||
Select-Object Temperature,Wear,
|
||||
ReadErrorsTotal,WriteErrorsTotal,
|
||||
PowerOnHours |
|
||||
Format-List
|
||||
}
|
||||
catch {
|
||||
Write-Output "Storage reliability counters unavailable."
|
||||
}
|
||||
}
|
||||
}
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Installed applications
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"INSTALLED PROGRAMS",
|
||||
powershell(r"""
|
||||
$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 |
|
||||
Sort-Object DisplayName -Unique |
|
||||
Format-Table -AutoSize
|
||||
""", timeout=120),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Startup
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"STARTUP PROGRAMS",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_StartupCommand |
|
||||
Select-Object Name,Command,Location,User |
|
||||
Sort-Object Name |
|
||||
Format-Table -Wrap -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"STARTUP FOLDERS",
|
||||
powershell(r"""
|
||||
$folders = @(
|
||||
"$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup",
|
||||
"$env:ProgramData\Microsoft\Windows\Start Menu\Programs\Startup"
|
||||
)
|
||||
|
||||
foreach ($folder in $folders) {
|
||||
Write-Output ""
|
||||
Write-Output "Folder: $folder"
|
||||
|
||||
if (Test-Path $folder) {
|
||||
Get-ChildItem $folder -Force |
|
||||
Select-Object Name,FullName,LastWriteTime |
|
||||
Format-Table -AutoSize
|
||||
}
|
||||
}
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Services
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"AUTOMATIC SERVICES",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_Service |
|
||||
Where-Object {$_.StartMode -eq 'Auto'} |
|
||||
Select-Object Name,DisplayName,State,StartMode,StartName |
|
||||
Sort-Object State,DisplayName |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"AUTOMATIC SERVICES THAT ARE NOT RUNNING",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_Service |
|
||||
Where-Object {
|
||||
$_.StartMode -eq 'Auto' -and
|
||||
$_.State -ne 'Running'
|
||||
} |
|
||||
Select-Object Name,DisplayName,State,StartMode |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Drivers / devices
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"SIGNED DRIVERS",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_PnPSignedDriver |
|
||||
Where-Object {$_.DeviceName} |
|
||||
Select-Object DeviceName,Manufacturer,
|
||||
DriverVersion,DriverDate |
|
||||
Sort-Object DeviceName |
|
||||
Format-Table -AutoSize
|
||||
""", timeout=120),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"DEVICES WITH PROBLEMS",
|
||||
powershell(r"""
|
||||
Get-PnpDevice -PresentOnly -ErrorAction SilentlyContinue |
|
||||
Where-Object {$_.Status -ne 'OK'} |
|
||||
Select-Object Status,Class,FriendlyName,InstanceId |
|
||||
Format-Table -Wrap -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Windows Update / hotfixes
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"INSTALLED WINDOWS UPDATES / HOTFIXES",
|
||||
powershell(r"""
|
||||
Get-HotFix |
|
||||
Sort-Object InstalledOn -Descending |
|
||||
Select-Object HotFixID,Description,InstalledBy,InstalledOn |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Windows Defender
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"WINDOWS DEFENDER STATUS",
|
||||
powershell(r"""
|
||||
if (Get-Command Get-MpComputerStatus -ErrorAction SilentlyContinue) {
|
||||
Get-MpComputerStatus |
|
||||
Select-Object AntivirusEnabled,
|
||||
AntispywareEnabled,
|
||||
RealTimeProtectionEnabled,
|
||||
BehaviorMonitorEnabled,
|
||||
IoavProtectionEnabled,
|
||||
AntivirusSignatureLastUpdated,
|
||||
QuickScanAge,
|
||||
FullScanAge |
|
||||
Format-List
|
||||
}
|
||||
else {
|
||||
Write-Output "Microsoft Defender cmdlets unavailable."
|
||||
}
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Network
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"NETWORK ADAPTERS",
|
||||
powershell(r"""
|
||||
Get-NetAdapter -ErrorAction SilentlyContinue |
|
||||
Select-Object Name,InterfaceDescription,Status,
|
||||
LinkSpeed,MacAddress |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"IP CONFIGURATION",
|
||||
run("ipconfig /all"),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"DNS SERVERS",
|
||||
powershell(r"""
|
||||
Get-DnsClientServerAddress |
|
||||
Where-Object {$_.ServerAddresses.Count -gt 0} |
|
||||
Select-Object InterfaceAlias,AddressFamily,
|
||||
@{N='Servers';E={$_.ServerAddresses -join ', '}} |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Power / battery
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"POWER PLAN",
|
||||
run("powercfg /getactivescheme"),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"BATTERY",
|
||||
powershell(r"""
|
||||
Get-CimInstance Win32_Battery -ErrorAction SilentlyContinue |
|
||||
Select-Object Name,Status,EstimatedChargeRemaining,
|
||||
EstimatedRunTime,BatteryStatus |
|
||||
Format-List
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# System uptime
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"UPTIME",
|
||||
powershell(r"""
|
||||
$os = Get-CimInstance Win32_OperatingSystem
|
||||
$uptime = (Get-Date) - $os.LastBootUpTime
|
||||
|
||||
[PSCustomObject]@{
|
||||
LastBoot = $os.LastBootUpTime
|
||||
Days = $uptime.Days
|
||||
Hours = $uptime.Hours
|
||||
Minutes = $uptime.Minutes
|
||||
} | Format-List
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Event logs
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"RECENT SYSTEM ERRORS - LAST 7 DAYS",
|
||||
powershell(r"""
|
||||
$start = (Get-Date).AddDays(-7)
|
||||
|
||||
Get-WinEvent -FilterHashtable @{
|
||||
LogName='System'
|
||||
Level=2
|
||||
StartTime=$start
|
||||
} -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 100 TimeCreated,Id,ProviderName,Message |
|
||||
Format-List
|
||||
""", timeout=120),
|
||||
)
|
||||
|
||||
section(
|
||||
f,
|
||||
"RECENT APPLICATION ERRORS - LAST 7 DAYS",
|
||||
powershell(r"""
|
||||
$start = (Get-Date).AddDays(-7)
|
||||
|
||||
Get-WinEvent -FilterHashtable @{
|
||||
LogName='Application'
|
||||
Level=2
|
||||
StartTime=$start
|
||||
} -ErrorAction SilentlyContinue |
|
||||
Select-Object -First 100 TimeCreated,Id,ProviderName,Message |
|
||||
Format-List
|
||||
""", timeout=120),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Scheduled tasks
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"NON-MICROSOFT SCHEDULED TASKS",
|
||||
powershell(r"""
|
||||
Get-ScheduledTask -ErrorAction SilentlyContinue |
|
||||
Where-Object {
|
||||
$_.TaskPath -notlike '\Microsoft\*'
|
||||
} |
|
||||
Select-Object TaskName,TaskPath,State |
|
||||
Sort-Object TaskPath,TaskName |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Processes
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"TOP PROCESSES BY MEMORY",
|
||||
powershell(r"""
|
||||
Get-Process |
|
||||
Sort-Object WorkingSet64 -Descending |
|
||||
Select-Object -First 30
|
||||
ProcessName,Id,
|
||||
@{N='MemoryMB';E={[math]::Round($_.WorkingSet64/1MB,1)}},
|
||||
CPU |
|
||||
Format-Table -AutoSize
|
||||
"""),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# System file / Windows maintenance status
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"WINDOWS COMPONENT STORE STATUS",
|
||||
run(
|
||||
"DISM /Online /Cleanup-Image /CheckHealth",
|
||||
timeout=120
|
||||
),
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Environment / filesystem
|
||||
# ------------------------------------------------------------------
|
||||
section(
|
||||
f,
|
||||
"IMPORTANT WINDOWS DIRECTORIES",
|
||||
f"""
|
||||
Windows directory : {os.environ.get('WINDIR')}
|
||||
System drive : {os.environ.get('SystemDrive')}
|
||||
Program Files : {os.environ.get('ProgramFiles')}
|
||||
Program Files x86 : {os.environ.get('ProgramFiles(x86)')}
|
||||
ProgramData : {os.environ.get('ProgramData')}
|
||||
User profile : {os.environ.get('USERPROFILE')}
|
||||
TEMP : {os.environ.get('TEMP')}
|
||||
""",
|
||||
)
|
||||
|
||||
print()
|
||||
print("Report completed.")
|
||||
print(f"Saved to: {REPORT.resolve()}")
|
||||
Loading…
Reference in New Issue