why -whatif (GUI) in the foreach?

This topic contains 4 replies, has 3 voices, and was last updated by  Jeff Taylor 1 year, 11 months ago.

  • Author
  • #47653

    Jeff Taylor


    Wondering why I am getting prompted by the GUI -whatif for the following one-liner where it is not explicitly set?

    foreach ($user in $Users) {Remove-ADUser $user.samAccountName -Credential $creds}

    ...because I am attempting to delete 400 Users but am getting prompted for each of them.

    thank you

  • #47655

    Dave Wyatt

    Commands have an attribute called ConfirmImpact. By default, any command with a ConfirmImpact of 'High' will prompt you unless you explicitly tell PowerShell not to (such as with -Confirm:$false).

    • #47657

      Jeff Taylor

      Dave, worked a charm and many thanks for the speedy reply. Much appreciated

  • #47710

    Richard Siddaway

    Just to be 100% accurate you're getting prompted for a confirmation not a whatif. -Whatif parameter just produces a statement saying it would do something not a prompt to confirm an action

    • #47795

      Jeff Taylor

      100% understood Richard and thank you for clarifying.

You must be logged in to reply to this topic.