Tests/MSFT_xWindowsProcess.TestHelper.psm1

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
$errorActionPreference = 'Stop'
Set-StrictMode -Version 'Latest'

<#
    .SYNOPSIS
        Stops all instances of the process with the given name.
 
    .PARAMETER ProcessName
        The name of the process to stop.
#>

function Stop-ProcessByName
{
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory = $true)]
        [String]
        $ProcessName
    )

    Stop-Process -Name $ProcessName -ErrorAction 'SilentlyContinue' -Force
    Wait-ScriptBlockReturnTrue -ScriptBlock { return $null -eq (Get-Process -Name $ProcessName -ErrorAction 'SilentlyContinue') } `
                               -TimeoutSeconds 15
}

Export-ModuleMember -Function Stop-ProcessByName