Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,20 @@ title: Confirmation Messages
# Confirmation Messages

Here are different confirmation messages that can be displayed depending on the variants of the
[System.Management.Automation.Cmdlet.ShouldProcess](/dotnet/api/System.Management.Automation.Cmdlet.ShouldProcess)
and
[System.Management.Automation.Cmdlet.ShouldContinue](/dotnet/api/System.Management.Automation.Cmdlet.ShouldContinue)
methods that are called.
[System.Management.Automation.Cmdlet.ShouldProcess][04] and
[System.Management.Automation.Cmdlet.ShouldContinue][03] methods that are called.

> [!IMPORTANT]
> For sample code that shows how to request confirmations, see
> [How to Request Confirmations](./how-to-request-confirmations.md).
> [Requesting Confirmation from Cmdlets][01].

## Specifying the Resource

You can specify the resource that is about to be changed by calling the
[System.Management.Automation.Cmdlet.ShouldProcess](/dotnet/api/System.Management.Automation.Cmdlet.ShouldProcess)
method. In this case, you supply the resource by using the `target` parameter of the method, and the
operation is added by Windows PowerShell. In the following message, the text "MyResource" is the
resource acted on and the operation is the name of the command that makes the call.
[System.Management.Automation.Cmdlet.ShouldProcess][04] method. In this case, you supply the
resource by using the `target` parameter of the method, and the operation is added by Windows
PowerShell. In the following message, the text "MyResource" is the resource acted on and the
operation is the name of the command that makes the call.

```Output
Confirm
Expand All @@ -31,9 +29,8 @@ Performing operation "Test-RequestConfirmationTemplate1" on Target "MyResource".
```

If the user selects **Yes** or **Yes to All** to the confirmation request (as shown in the following
example), a call to the
[System.Management.Automation.Cmdlet.ShouldContinue](/dotnet/api/System.Management.Automation.Cmdlet.ShouldContinue)
method is made, which causes a second confirmation message to be displayed.
example), a call to the [System.Management.Automation.Cmdlet.ShouldContinue][03] method is made,
which causes a second confirmation message to be displayed.

```Output
Confirm
Expand All @@ -49,11 +46,10 @@ Continue with this operation?
## Specifying the Operation and Resource

You can specify the resource that is about to be changed and the operation that the command is about
to perform by calling the
[System.Management.Automation.Cmdlet.ShouldProcess](/dotnet/api/System.Management.Automation.Cmdlet.ShouldProcess)
method. In this case, you supply the resource by using the `target` parameter and the operation by
using the `target` parameter. In the following message, the text "MyResource" is the resource acted
on and "MyAction" is the operation to be performed.
to perform by calling the [System.Management.Automation.Cmdlet.ShouldProcess][04] method. In this
case, you supply the resource by using the `target` parameter and the operation by using the
`target` parameter. In the following message, the text "MyResource" is the resource acted on and
"MyAction" is the operation to be performed.

```Output
Confirm
Expand All @@ -63,8 +59,8 @@ Performing operation "MyAction" on Target "MyResource".
```

If the user selects **Yes** or **Yes to All** to the previous message, a call to the
[System.Management.Automation.Cmdlet.ShouldContinue](/dotnet/api/System.Management.Automation.Cmdlet.ShouldContinue)
method is made, which causes a second confirmation message to be displayed.
[System.Management.Automation.Cmdlet.ShouldContinue][03] method is made, which causes a second
confirmation message to be displayed.

```Output
Confirm
Expand All @@ -79,4 +75,10 @@ Continue with this operation?

## See Also

[Writing a Windows PowerShell Cmdlet](./writing-a-windows-powershell-cmdlet.md)
[Writing a Windows PowerShell Cmdlet][02]

<!-- link references -->
[01]: ./requesting-confirmation-from-cmdlets.md
[02]: ./writing-a-windows-powershell-cmdlet.md
[03]: xref:System.Management.Automation.Cmdlet.ShouldContinue%2A
[04]: xref:System.Management.Automation.Cmdlet.ShouldProcess%2A

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,54 @@ title: Examples of Cmdlet Code
This section contains examples of cmdlet code that you can use to start writing your own cmdlets.

> [!IMPORTANT]
> If you want step-by-step instructions for writing cmdlets, see [Tutorials for Writing Cmdlets](./tutorials-for-writing-cmdlets.md).
> If you want step-by-step instructions for writing cmdlets, see [Tutorials for Writing Cmdlets][12].

## In This Section

[How to Write a Simple Cmdlet](./how-to-write-a-simple-cmdlet.md)
This example shows the basic structure of cmdlet code.

[How to Declare Cmdlet Parameters](./how-to-declare-cmdlet-parameters.md)
This example shows how to declare the different types of parameters.

[How to Declare Parameter Sets](./how-to-declare-parameter-sets.md)
This example shows how to declare sets of parameters that can change the action a cmdlet performs.

[How to Validate Parameter Input](./how-to-validate-parameter-input.md)
These examples show how to validate parameter input.

[How to Declare Dynamic Parameters](./how-to-declare-dynamic-parameters.md)
This example shows how to declare a parameter that is added at runtime.

[How to Invoke Scripts Within a Cmdlet](./how-to-invoke-scripts-within-a-cmdlet.md)
This example shows how to invoke a script that is supplied to a cmdlet.

[How To Override Input Processing Methods](./how-to-override-input-processing-methods.md)
These examples show the basic structure used to override the BeginProcessing, ProcessRecord, and EndProcessing methods.

[How to Support ShouldProcess Calls](./how-to-request-confirmations.md)
This example shows how the [System.Management.Automation.Cmdlet.ShouldProcess](/dotnet/api/System.Management.Automation.Cmdlet.ShouldProcess) and [System.Management.Automation.Cmdlet.ShouldContinue](/dotnet/api/System.Management.Automation.Cmdlet.ShouldContinue) methods should be called from within a cmdlet.

[How to Support Transactions](./how-to-support-transactions.md)
This example shows how to indicate that the cmdlet supports transactions and how to implement the action that is taken when the cmdlet is used within a transaction.

[How to Support Jobs](./how-to-support-jobs.md)
This example shows how to support jobs when you write cmdlets.

[How to Invoke a Cmdlet From Within a Cmdlet](./how-to-invoke-a-cmdlet-from-within-a-cmdlet.md)
This example shows how to invoke a cmdlet from within another cmdlet, which allows you to add the functionality of the invoked cmdlet to the cmdlet you are developing.
- [How to Write a Simple Cmdlet][11] - This example shows the basic structure of cmdlet code.
- [How to Declare Cmdlet Parameters][01] - This example shows how to declare the different types of
parameters.
- [How to Declare Parameter Sets][03] - This example shows how to declare sets of parameters that
can change the action a cmdlet performs.
- [How to Validate Parameter Input][10] - These examples show how to validate parameter input.
- [How to Declare Dynamic Parameters][02] - This example shows how to declare a parameter that is
added at runtime.
- [How to Invoke Scripts Within a Cmdlet][05] - This example shows how to invoke a script that is
supplied to a cmdlet.
- [How To Override Input Processing Methods][06] - These examples show the basic structure used to
override the BeginProcessing, ProcessRecord, and EndProcessing methods.
- [How to Support ShouldProcess Calls][07] - This example shows how the
[System.Management.Automation.Cmdlet.ShouldProcess][15] and
[System.Management.Automation.Cmdlet.ShouldContinue][14] methods should be called from within a
cmdlet.
- [How to Support Transactions][09] - This example shows how to indicate that the cmdlet supports
transactions and how to implement the action that is taken when the cmdlet is used within a
transaction.
- [How to Support Transactions][09] - This example shows how to indicate that the cmdlet supports
transactions and how to implement the action that is taken when the cmdlet is used within a
transaction.
- [How to Support Jobs][08] - This example shows how to support jobs when you write cmdlets.
- [How to Invoke a Cmdlet From Within a Cmdlet][04] - This example shows how to invoke a cmdlet from
within another cmdlet, which allows you to add the functionality of the invoked cmdlet to the
cmdlet you are developing.

## See Also

[Writing a Windows PowerShell Cmdlet](./writing-a-windows-powershell-cmdlet.md)
[Writing a Windows PowerShell Cmdlet][13]

<!-- link references -->
[01]: ./how-to-declare-cmdlet-parameters.md
[02]: ./how-to-declare-dynamic-parameters.md
[03]: ./how-to-declare-parameter-sets.md
[04]: ./how-to-invoke-a-cmdlet-from-within-a-cmdlet.md
[05]: ./how-to-invoke-scripts-within-a-cmdlet.md
[06]: ./how-to-override-input-processing-methods.md
[07]: ./requesting-confirmation-from-cmdlets.md
[08]: ./how-to-support-jobs.md
[09]: ./how-to-support-transactions.md
[10]: ./how-to-validate-parameter-input.md
[11]: ./how-to-write-a-simple-cmdlet.md
[12]: ./tutorials-for-writing-cmdlets.md
[13]: ./writing-a-windows-powershell-cmdlet.md
[14]: /dotnet/api/System.Management.Automation.Cmdlet.ShouldContinue
[15]: /dotnet/api/System.Management.Automation.Cmdlet.ShouldProcess
Loading
Loading