从通讯组中删除用户,而无需其他确认 [英] Remove users from distribution groups without additional confirmation

查看:54
本文介绍了从通讯组中删除用户,而无需其他确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面有可以使用的交流powershell脚本,但是我对powershell脚本了解不多,因此希望我可以在如何实现相同想法方面获得一些帮助,但不必确认将用户从脚本运行时每个组.基本上想运行脚本,删除用户并完成脚本,而无需任何其他确认.如果需要任何其他信息,请告诉我.

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
    }

推荐答案

浏览

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

确认"开关可用于禁止显示确认提示,该提示在运行此cmdlet时默认出现.要取消确认提示,请使用语法-Confirm:$ False.您必须在语法中包含一个冒号(:).

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
}

这篇关于从通讯组中删除用户,而无需其他确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆