wondergoat77
wondergoat77

Reputation: 1805

Remove users from distribution groups without additional confirmation

I have the exchange powershell script below that works, but I don't know a lot about powershell script so hoping i could get some help in how I can have this same idea work, but not have to confirm removing the user from each group as the script runs. Basically want to run the script, remove the user and be done with it without any additional confirmation needed. If any additional information is needed, please let me know.

    $user = "[email protected]"
    $groups = Get-DistributionGroup
    $DGs = $groups | where-object { ( Get-DistributionGroupMember $_ | where-object { $_.PrimarySmtpAddress -contains $user}) } 

    foreach( $dg in $DGs){
        Remove-DistributionGroupMember $dg -Member $user
    }

Upvotes: 0

Views: 13360

Answers (1)

E.V.I.L.
E.V.I.L.

Reputation: 2166

Looking through the documentation on Remove-DistributionGroupMember under the -Confirm parameter they say:

The Confirm switch can be used to suppress the confirmation prompt that appears by default when this cmdlet is run. To suppress the confirmation prompt, use the syntax -Confirm:$False. You must include a colon ( : ) in the syntax.

So to surpress the prompt it looks like all you need to do is this:

foreach( $dg in $DGs){
    Remove-DistributionGroupMember $dg -Member $user -Confirm:$False
}

Upvotes: 3

Related Questions