-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiagnoseComputer.ps1
More file actions
61 lines (49 loc) · 3.18 KB
/
DiagnoseComputer.ps1
File metadata and controls
61 lines (49 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Function to get formatted output
function Format-Output {
param ($Title, $Data)
Write-Output "`n=== $Title ===`n$Data`n"
}
# System Information
$systemInfo = Get-ComputerInfo | Select-Object WindowsProductName, WindowsVersion, OsHardwareAbstractionLayer, CsManufacturer, CsModel, CsProcessors, CsNumberOfLogicalProcessors, CsNumberOfProcessors, CsTotalPhysicalMemory
Format-Output "System Information" ($systemInfo | Format-List | Out-String)
# Disk Information
$diskInfo = Get-Disk | Select-Object Number, FriendlyName, MediaType, OperationalStatus, HealthStatus, Size, PartitionStyle
Format-Output "Disk Information" ($diskInfo | Format-Table -AutoSize | Out-String)
# Network Information
$networkInfo = Get-NetAdapter | Where-Object Status -eq "Up" | Select-Object Name, InterfaceDescription, MacAddress, LinkSpeed
$ipConfig = Get-NetIPConfiguration | Select-Object InterfaceAlias, IPv4Address, IPv6Address
Format-Output "Network Information" (($networkInfo | Format-Table -AutoSize | Out-String) + ($ipConfig | Format-Table -AutoSize | Out-String))
# Installed Software
$installedSoftware = Get-WmiObject -Class Win32_Product | Select-Object Name, Version, Vendor | Sort-Object Name
Format-Output "Installed Software (Top 20)" ($installedSoftware | Select-Object -First 20 | Format-Table -AutoSize | Out-String)
# Running Processes
$processes = Get-Process | Sort-Object CPU -Descending | Select-Object ProcessName, Id, CPU, WorkingSet, StartTime -First 20
Format-Output "Top 20 Running Processes by CPU Usage" ($processes | Format-Table -AutoSize | Out-String)
# Services Status
$services = Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object Name, DisplayName, Status -First 20
Format-Output "Top 20 Running Services" ($services | Format-Table -AutoSize | Out-String)
# Windows Updates
if (Get-Module -ListAvailable -Name PSWindowsUpdate) {
Import-Module PSWindowsUpdate
$updates = Get-WindowsUpdate
Format-Output "Available Windows Updates" ($updates | Format-Table -AutoSize | Out-String)
} else {
Write-Output "PSWindowsUpdate module not available. Skipping Windows Update check."
}
# System Event Logs (Last 10 Error events)
$eventLogs = Get-EventLog -LogName System -EntryType Error -Newest 10 | Select-Object TimeGenerated, Source, EventID, Message
Format-Output "Recent System Error Logs" ($eventLogs | Format-Table -AutoSize | Out-String)
# CPU Usage
$cpuUsage = (Get-Counter '\Processor(_Total)\% Processor Time').CounterSamples.CookedValue
Format-Output "Current CPU Usage" "$cpuUsage%"
# Memory Usage
$os = Get-Ciminstance Win32_OperatingSystem
$memoryUsage = [math]::Round(($os.TotalVisibleMemorySize - $os.FreePhysicalMemory) / $os.TotalVisibleMemorySize * 100, 2)
Format-Output "Current Memory Usage" "$memoryUsage%"
# Disk Space
$diskSpace = Get-WmiObject Win32_LogicalDisk | Where-Object {$_.DriveType -eq 3} |
Select-Object DeviceID, VolumeName,
@{Name="Size(GB)";Expression={[math]::Round($_.Size/1GB,2)}},
@{Name="FreeSpace(GB)";Expression={[math]::Round($_.FreeSpace/1GB,2)}},
@{Name="UsedSpace(%)";Expression={[math]::Round(($_.Size - $_.FreeSpace) / $_.Size * 100,2)}}
Format-Output "Disk Space Usage" ($diskSpace | Format-Table -AutoSize | Out-String)