Skip to content

Invoke NativeCommand

dscbot edited this page Sep 20, 2026 · 1 revision

Invoke-NativeCommand

SYNOPSIS

Invokes a native command with an argument array.

SYNTAX

Invoke-NativeCommand [-Executable] <String> [-Sudo] [[-SudoAs] <String>] [[-Parameters] <String[]>]
 [<CommonParameters>]

DESCRIPTION

Invokes an executable without constructing PowerShell source code, optionally applies sudo preferences on Linux or macOS, and redirects standard error into the success stream for downstream parsing.

EXAMPLES

EXAMPLE 1

Invoke-NativeCommand -Executable 'git' -Parameters '--version'

Invokes git and returns its combined standard output and standard error.

PARAMETERS

-Executable

Specifies the native executable or command to invoke.

Type: String
Parameter Sets: (All)
Aliases: Command

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Parameters

Specifies native argument values in their required order.

Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Sudo

Invokes the command through sudo on Linux or macOS.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-SudoAs

Invokes the command through sudo -u for the specified user on Linux or macOS.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: 2
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

NOTES

RELATED LINKS