powershelliis

PowerShell IISAdministration: use of "-Confirm" parameter


For our reverse proxy configuration script, I need to remove current configuration elements from a collection, then add the ones we need.

Using Clear-IISCOnfigCollection, I can do what I want; after lots of experimentation, however, I have been unable to find a way around the prompt

Confirm
Are you sure you want to perform this action?
Performing the operation "Clear-IISConfigCollection" on target "Collection".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):  

I tried using the -Confirm parameter, however, this parameter takes no argument and does not change the behaviour of the command - it still asks a question that a user of the script cannot answer.

I already tried if -Force would help, to no avail - it is not known by Clear-IISConfigCollection.

Does anyone know of a way to get this command to execute without prompting?


Solution

  • Aside from -Confirm:$False

    you can also change the $ConfirmPreference variable in your session or add it to the top of your script. Valid values are High, Medium, or Low.

    $ConfirmPreference=Low
    

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.4#confirmpreference