First release

This commit is contained in:
iminet
2026-02-04 09:37:25 +01:00
parent c1df35ef4a
commit 735b3d1a96
2 changed files with 62 additions and 0 deletions

7
src/ProcessStats.psd1 Normal file
View File

@@ -0,0 +1,7 @@
New-ModuleManifest `
-Path ProcessStats.psd1 `
-RootModule ProcessStats.psm1 `
-ModuleVersion 1.0.0 `
-Author "Iminetsoft" `
-Description "Analyze memory and CPU usage of duplicate processes" `
-PowerShellVersion 5.1

55
src/ProcessStats.psm1 Normal file
View File

@@ -0,0 +1,55 @@
<#
.SYNOPSIS
PowerShell module to analyze duplicated processes' memory and CPU usage.
#>
# -----------------------
# Cmdlet 1: Memory Usage
# -----------------------
function Get-ProcessMemory {
[CmdletBinding()]
param(
[int]$MinCount = 2
)
Get-Process |
Group-Object Name |
Where-Object Count -ge $MinCount |
ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Count = $_.Count
'Memory Sum in MB' = [math]::Round(
(($_.Group | Measure-Object WorkingSet -Sum).Sum / 1MB), 3
)
}
} |
Sort-Object 'Memory Sum in MB' -Descending
}
# -----------------------
# Cmdlet 2: CPU Usage
# -----------------------
function Get-ProcessCPU {
[CmdletBinding()]
param(
[int]$MinCount = 2
)
Get-Process |
Group-Object Name |
Where-Object Count -ge $MinCount |
ForEach-Object {
[PSCustomObject]@{
Name = $_.Name
Count = $_.Count
'CPU Total (%)' = [math]::Round(
($_.Group | Measure-Object CPU -Sum).Sum, 2
)
}
} |
Sort-Object 'CPU Total (%)' -Descending
}
# Export both cmdlets
Export-ModuleMember -Function Get-ProcessMemory, Get-ProcessCPU