private/Invoke-External.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
26
27
28
29
30
31
32
33
34
35
36
37
<#
.SYNOPSIS
Helper function for invoking an external utility (executable).
The raison d'être for this function is to allow calls to external executables via their *full paths* to be mocked in Pester.
 
.DESCRIPTION
See source for more information : https://stackoverflow.com/questions/37926844/how-to-mock-a-call-to-an-exe-file-with-pester
 
.PARAMETER LiteralPath
Literal path to the executable ("...\nuget.exe", "npm")
 
.PARAMETER PassThruArgs
Arguments to be passed to the executable
 
.EXAMPLE
Invoke-External -l "npm" install -g $npmPackage | Out-Null
#>


Function Invoke-External {

  [CmdletBinding()]
    param(
      [Parameter(Mandatory=$true)]
      [string] $LiteralPath,
      [Parameter(ValueFromRemainingArguments=$true)]
      $PassThruArgs
    )

    BEGIN {}

    PROCESS {
        & $LiteralPath $PassThruArgs
    } #PROCESS

    END {}
}