问题
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 = "user@domain.com"
$groups = Get-DistributionGroup
$DGs = $groups | where-object { ( Get-DistributionGroupMember $_ | where-object { $_.PrimarySmtpAddress -contains $user}) }
foreach( $dg in $DGs){
Remove-DistributionGroupMember $dg -Member $user
}
回答1:
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
}
来源:https://stackoverflow.com/questions/21534054/remove-users-from-distribution-groups-without-additional-confirmation