Say No to All on Confirm?

Welcome Forums General PowerShell Q&A Say No to All on Confirm?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 7 months ago.

  • Author
    Posts
  • #25074

    Participant
    Points: 0
    Rank: Member

    Hi,

    I know I can use -Confirm:$false so supress any Confirm messages.
    But what if I want my script to run unattended and answer 'No' to any Confirm Message?

    /Simon

  • #25077

    Participant
    Points: 0
    Rank: Member

    You could set $ConfirmPreference to None

    see about_Preference_Variables

    Whether this is a good idea or not is another debate 🙂

  • #25080

    Participant
    Points: 0
    Rank: Member

    yes, but that would have the same effect as using -Confirm:$false wouldnt it?

    I wanted my script to run but if there is a Confirm-message it should be answered with 'No'

    What I wanted to do was to call New-xDSCResource multiple times.

    If the resource doesnt exist it is created, if it does exist you get a Confirm-question.
    Answering No the the Confirm will write a warning instead of overwriting the resource and after that the resource is still validated against the arguments to New-xDSCresource.
    A simple way to confirm that no-one changed the properties.

    I know that I can use Test-xDscResource for a similar validation, but it will only validate that the resource is correct and won't detect if new properties are added.

The topic ‘Say No to All on Confirm?’ is closed to new replies.