Recall & Review
beginner
What does the
-WhatIf parameter do in PowerShell?It shows what would happen if a command runs, without actually making any changes. It's like a preview or a dry run.
Click to reveal answer
beginner
What is the purpose of the
-Confirm parameter in PowerShell?It asks you to confirm before running a command that changes something. You get a yes/no question to avoid mistakes.
Click to reveal answer
intermediate
How do you add
-WhatIf support to your own PowerShell function?Add
[CmdletBinding(SupportsShouldProcess=$true)] at the top and use $PSCmdlet.ShouldProcess() inside your function to check if it should run.Click to reveal answer
beginner
What happens if you run a command with
-Confirm and answer 'No'?The command stops and does not make any changes. This helps prevent unwanted actions.
Click to reveal answer
beginner
Why is it good practice to support
-WhatIf and -Confirm in scripts?It helps users avoid mistakes by previewing changes and asking for confirmation, making scripts safer to run.
Click to reveal answer
What does the
-WhatIf parameter do when added to a PowerShell command?✗ Incorrect
-WhatIf previews the command's effect without changing anything.
Which attribute enables
-WhatIf support in a PowerShell function?✗ Incorrect
This attribute tells PowerShell the function supports -WhatIf and -Confirm.
What does the
$PSCmdlet.ShouldProcess() method do inside a function?✗ Incorrect
It checks if the user wants to proceed, respecting -WhatIf and -Confirm.
If you run a command with
-Confirm and choose 'No', what happens?✗ Incorrect
Answering 'No' cancels the command to prevent changes.
Why should script authors add
-WhatIf and -Confirm support?✗ Incorrect
These features help users avoid mistakes by previewing and confirming actions.
Explain how to add WhatIf and Confirm support to a PowerShell function.
Think about the attribute and method that enable this support.
You got /3 concepts.
Describe the difference between -WhatIf and -Confirm parameters in PowerShell.
One previews, the other asks permission.
You got /3 concepts.