Domanda

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
    }
È stato utile?

Soluzione

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
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top