Is it possible to add members to a DistributionGroup using a variable. Importing a CSV file works but can be time consuming.
variable
$users = Get-Mailbox -Filter {RecipientTypeDetails -eq "UserMailbox"}
Adding the members, if I try to pipe foreach after the Add-DistributionGroupMember cmdlet the -Member parameter is missing.
PS C:\Windows\System32\WindowsPowerShell\v1.0> $users | foreach {Add-DistributionGroupMember -Identity EveryoneGroup -Member $_.users} Cannot validate argument on parameter 'Member'. The argument is null. Supply a non-null argument and try the command again. + CategoryInfo : InvalidData: (:) [Add-DistributionGroupMember], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-DistributionGroupMember + PSComputerName : outlook.office365.com
I’m probably doing something very stupid here…