Functions/HealthCheck/Processes/Get-AMHCDuplicateProcess.ps1

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
function Get-AMHCDuplicateProcess {
    <#
        .SYNOPSIS
            Duplicate Processes
 
        .DESCRIPTION
            Processes that have the same Command Line/Working Directory/Environment Variables/Running Context as another process
 
        .PARAMETER Processes
            The processes to perform health check against
    #>

    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [AllowNull()]
        $Processes
    )

    $grouping = $Processes | Group-Object CommandLine,WorkingDirectory,EnvironmentVariables,RunProcessAs
    foreach ($group in ($grouping | Where-Object {$_.Count -gt 1})) {
        foreach ($process in $group.Group) {
            [AMConstructHealthCheckItem]::New($process, "Duplicates: $($group.Group.Name -join " ,")")
        }
    }
}