why -whatif (GUI) in the foreach?

Tagged: 

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Jeff Taylor Jeff Taylor 4 months, 2 weeks ago.

  • Author
    Posts
  • #47653
    Profile photo of Jeff Taylor
    Jeff Taylor
    Participant

    Hello,

    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
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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
      Profile photo of Jeff Taylor
      Jeff Taylor
      Participant

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

  • #47710
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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
      Profile photo of Jeff Taylor
      Jeff Taylor
      Participant

      100% understood Richard and thank you for clarifying.

You must be logged in to reply to this topic.