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 2 months, 1 week ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • 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

    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.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.