< Back

Test-PSFShouldProcess

Sun Jan 19, 2020 6:45 pm

NAME Test-PSFShouldProcess



SYNOPSIS

Implements the shouldprocess question.





SYNTAX

Test-PSFShouldProcess [-PSCmdlet <PSCmdlet>] -Target <String> -Action <String> [-Confirm] [-WhatIf]

[<CommonParameters>]



Test-PSFShouldProcess [-PSCmdlet <PSCmdlet>] -Target <String> -ActionString <String> [-ActionStringValues

<Object[]>] [-Confirm] [-WhatIf] [<CommonParameters>]





DESCRIPTION

This command can be used in other commands to implement the ShouldProcess question asked if using the command

requires confirmation. This replaces / wraps the traditional ShouldProcess call, makes it easier to read in script

and allows mocking it.





PARAMETERS

-PSCmdlet <PSCmdlet>

The $PSCmdlet variable of the calling function. Used to ensure the actual prompt logic as intended is being

used.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Target <String>

The target that is being processed.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Action <String>

The action that will be performed on the target.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ActionString <String>

Localized string of the action that will be performed on the target. Omit the modulename in the string. For

more details on the PSFramework localization feature, see the help on Import-PSFLocalizedString.



Required? true

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-ActionStringValues <Object[]>

Specify values to format into the localization string specified. For more details on the PSFramework

localization feature, see the help on Import-PSFLocalizedString.



Required? false

Position? named

Default value None

Accept pipeline input? False

Accept wildcard characters? false



-Confirm [<SwitchParameter>]

Prompts you for confirmation before running the cmdlet.



Required? false

Position? named

Default value False

Accept pipeline input? False

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]

Shows what would happen if the cmdlet runs. The cmdlet is not run.



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



NOTES









-------------------- Example 1: Basic Usage --------------------



if (Test-PSFShouldProcess -PSCmdlet $PSCmdlet -Target $item -Action "Performing some arbitrary action") {



}



This will test whether the user should be prompted for confirmation, will do so if necessary and report back the

results.



RELATED LINKS

Online Documentation https://psframework.org/documentation/c ... ocess.html