< Back
Invoke-ProcessHelper
Post
NAME Invoke-ProcessHelper
SYNOPSIS
Utility function for executing processes with advance output/error handling options
SYNTAX
Invoke-ProcessHelper [-ProcessFileName] <String> [[-ProcessArguments] <String[]>] [[-WorkingDirectory] <String>]
[[-TempDirectory] <String>] [-DiscardStandardOut] [-DiscardStandardErr] [-LogToFile] [-RunasAdmin]
[<CommonParameters>]
DESCRIPTION
Utility function for executing processes with advance output/error handling options. This function
leverages the System.Diagnostics.ProcessStartInfo and System.Diagnostics.Process for invoking an
executable/batch file.
PARAMETERS
-ProcessFileName <String>
The path to the executable that will be invoked.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ProcessArguments <String[]>
The arguments that will be passed to the process if applicable.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WorkingDirectory <String>
The directory from which to invoke the process. It may be useful for batch files with relative paths.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-TempDirectory <String>
Path to a temporary directory to dump the standard out/err output. Used when switch LogToFile is specified.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-DiscardStandardOut [<SwitchParameter>]
If specified, the standard out will not be captured/returned.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-DiscardStandardErr [<SwitchParameter>]
If specified, the standard err will not be captured/returned.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-LogToFile [<SwitchParameter>]
Determines whether or not the standard output/error should be logged to a file. Default is to output to
console/in-memory.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-RunasAdmin [<SwitchParameter>]
If specified, the verb runas will be set on the ProcessStartInfo object.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\># Get the version information of IBM Installation Manager using their command line tool
Invoke-ProcessHelper "C:\\IBM\\IIM\\eclipse\\tools\\imcl.exe" @("-version")
-------------------------- EXAMPLE 2 --------------------------
PS C:\\># Log the version information of IBM Installation Manager to a temp file
Invoke-ProcessHelper "C:\\IBM\\IIM\\eclipse\\tools\\imcl.exe" @("-version") -LogToFile
RELATED LINKS
SYNOPSIS
Utility function for executing processes with advance output/error handling options
SYNTAX
Invoke-ProcessHelper [-ProcessFileName] <String> [[-ProcessArguments] <String[]>] [[-WorkingDirectory] <String>]
[[-TempDirectory] <String>] [-DiscardStandardOut] [-DiscardStandardErr] [-LogToFile] [-RunasAdmin]
[<CommonParameters>]
DESCRIPTION
Utility function for executing processes with advance output/error handling options. This function
leverages the System.Diagnostics.ProcessStartInfo and System.Diagnostics.Process for invoking an
executable/batch file.
PARAMETERS
-ProcessFileName <String>
The path to the executable that will be invoked.
Required? true
Position? 1
Default value
Accept pipeline input? false
Accept wildcard characters? false
-ProcessArguments <String[]>
The arguments that will be passed to the process if applicable.
Required? false
Position? 2
Default value
Accept pipeline input? false
Accept wildcard characters? false
-WorkingDirectory <String>
The directory from which to invoke the process. It may be useful for batch files with relative paths.
Required? false
Position? 3
Default value
Accept pipeline input? false
Accept wildcard characters? false
-TempDirectory <String>
Path to a temporary directory to dump the standard out/err output. Used when switch LogToFile is specified.
Required? false
Position? 4
Default value
Accept pipeline input? false
Accept wildcard characters? false
-DiscardStandardOut [<SwitchParameter>]
If specified, the standard out will not be captured/returned.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-DiscardStandardErr [<SwitchParameter>]
If specified, the standard err will not be captured/returned.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-LogToFile [<SwitchParameter>]
Determines whether or not the standard output/error should be logged to a file. Default is to output to
console/in-memory.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
-RunasAdmin [<SwitchParameter>]
If specified, the verb runas will be set on the ProcessStartInfo object.
Required? false
Position? named
Default value False
Accept pipeline input? false
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
-------------------------- EXAMPLE 1 --------------------------
PS C:\\># Get the version information of IBM Installation Manager using their command line tool
Invoke-ProcessHelper "C:\\IBM\\IIM\\eclipse\\tools\\imcl.exe" @("-version")
-------------------------- EXAMPLE 2 --------------------------
PS C:\\># Log the version information of IBM Installation Manager to a temp file
Invoke-ProcessHelper "C:\\IBM\\IIM\\eclipse\\tools\\imcl.exe" @("-version") -LogToFile
RELATED LINKS