Remove users from distribution groups without additional confirmation

天大地大妈咪最大 提交于 2019-12-12 02:34:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!