function Invoke-SCExe { <# .SYNOPSIS Used to call sc.exe. This function is basically just a wrapper for unit-testing purposes. .PARAMETER Arguments We have found that an array of strings is fine for sc.exe management. This value just gets splatted as passed in. #> [CmdletBinding()] [OutputType([System.Void])] param( [Parameter(Mandatory = $false)] [string[]]$Arguments = @() ) $logLead = Get-LogLeadName # Ensure we have an array $scArguments = @($Arguments) $output = "" try { $output = (Invoke-CallOperatorWithPathAndParameters "C:\WINDOWS\System32\sc.exe" $scArguments) # Is this always the only way to get an error? $didFailByExitCode = $LASTEXITCODE -ne 0 if ($didFailByExitCode) { Write-Warning "$logLead : sc.exe failed on run" throw "sc.exe failed to execute.`r`n$output" } } finally { Write-Verbose "$loglead : sc.exe output: $output" } }