Skip to content

Add SudoPreferenceRule

dscbot edited this page Sep 20, 2026 · 1 revision

Add-SudoPreferenceRule

SYNOPSIS

Adds or changes a sudo preference rule.

SYNTAX

Sudo

Add-SudoPreferenceRule -Executable <String> -ParameterFilterRule <Object> [-SudoUser <String>]
 [<CommonParameters>]

SudoAll

Add-SudoPreferenceRule [-EnableSudoForAllCommands] [-SudoUser <String>] 
 [<CommonParameters>]

NoSudoAll

Add-SudoPreferenceRule [-DisableSudoForAllCommands] [<CommonParameters>]

DESCRIPTION

Registers a command-specific sudo rule or enables or disables sudo for every native command. Parameter filters must be script blocks or the wildcard string '*'. Script blocks are retained without recompilation.

EXAMPLES

EXAMPLE 1

Add-SudoPreferenceRule -Executable 'dpkg' -ParameterFilterRule {
    $args -contains '--install'
}

Adds a rule that uses sudo for dpkg installation commands.

EXAMPLE 2

Add-SudoPreferenceRule -EnableSudoForAllCommands -SudoUser 'root'

Enables sudo for all native commands and selects the root user.

PARAMETERS

-DisableSudoForAllCommands

Disables the global sudo preference without deleting command rules.

Type: SwitchParameter
Parameter Sets: NoSudoAll
Aliases:

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

-EnableSudoForAllCommands

Enables sudo for every native command.

Type: SwitchParameter
Parameter Sets: SudoAll
Aliases:

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

-Executable

Specifies the executable to which the rule applies. Use '*' with a wildcard or constant script-block filter to configure all commands.

Type: String
Parameter Sets: Sudo
Aliases: Command

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

-ParameterFilterRule

Specifies '*' to match every argument list or a script block that evaluates the command arguments through its automatic $args variable.

Type: Object
Parameter Sets: Sudo
Aliases:

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

-SudoUser

Specifies the user supplied to sudo -u when the matching rule applies.

Type: String
Parameter Sets: Sudo, SudoAll
Aliases:

Required: False
Position: Named
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