-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_analyse_script.ps1
More file actions
92 lines (52 loc) · 2.5 KB
/
system_analyse_script.ps1
File metadata and controls
92 lines (52 loc) · 2.5 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#Create File only if it does not exist
$reportFile = "D:\PowerShell\SystemReport.txt"
if (!(Test-Path $reportFile))
{
New-Item -ItemType File $reportFile
}
else
{
"File Already Exist!"
}
$reportData = @() # Initialize an array to hold report data
$reportData += "=== System Health Report ==="
#Enter a date for report generate
$reportData += "Generated On: $(Get-Date)"
#Disk Usage Data
$reportData += "--- Disk Usage ---"
$reportData += Get-PSDrive -PSProvider FileSystem | Out-String
#CPU Usage Data
$reportData += "`n--- CPU Usage ---"
#Get-CimInstance retrieves system information using CIM (Common Information Model).
#The Win32_Processor class contains information about the processor(s) on the system, including their name and current load percentage.
#The output is converted to a string format for easier inclusion in the report.
#PowerShell uses CIM to communicate with Windows Management Instrumentation (WMI), which provides a standardized way to access system information.
$reportData += Get-CimInstance -ClassName Win32_Processor | Out-String
$reportData += Get-CimInstance -ClassName Win32_Processor | Select-Object Name, LoadPercentage | Out-String
#Memory Usage Data
$reportData += "`n--- Memory Usage ---"
# Fetch memory information from the Operating System
$osData = Get-CimInstance -ClassName Win32_OperatingSystem
# Calculate Total and Free Memory in GB (rounding to 2 decimal places)
$totalMemory = [Math]::Round($osData.TotalVisibleMemorySize / 1MB, 2)
$freeMemory = [Math]::Round($osData.FreePhysicalMemory / 1MB, 2)
# Calculate Percentage of Used and Free Memory
$freeMemoryPercentage = [Math]::Round(($freeMemory / $totalMemory) * 100, 2)
$usedMemoryPercentage = 100 - $freeMemoryPercentage
# Display final memory statistics
$reportData += "Memory Usage Summary:"
$reportData += "Used Memory: $usedMemoryPercentage %"
$reportData += "Free Memory: $freeMemoryPercentage %"
#Service Data
$reportData += "`n--- Service's Data ---"
# Get all running services and join their names with a comma
$runningServices = (Get-Service | Where-Object { $_.Status -eq "Running" }).Name -join ", "
# Get all stopped services and join their names with a comma
$stoppedServices = (Get-Service | Where-Object { $_.Status -eq "Stopped" }).Name -join ", "
# Output the formatted lists
$reportData += "-- Running Services --"
$reportData += $runningServices
$reportData += "-- Stopped Services --"
$reportData += $stoppedServices
#Write the report data to the file
$reportData | Set-Content $reportFile