Hi,
Probably a very simple resolution.
I would like to get the alias for users whos name starts with A,B or C from the get-mailbox command in Exchange. Then I want to take those users and add them to a group. Generally, Ive done this sort of thing with CSVs but id like to avoid that in this instance.
I can create a variable as below:
$AC = Get-Mailbox -RecipientTypeDetails UserMailbox -OrganizationalUnit $OUMbx | where {$_.DisplayName -Like "[A-C]*"}
When I run $AC, it does indeed list my users as expected.
Then I tried:
Get-ADUser Group-AC | Add-ADGroupMember -Members $AC
Add-ADGroupMember : Cannot validate argument on parameter 'Members'. The argument is null or empty. Supply an argument that is not null or empty and then try the command again.
I always thought I could do $AC.Alias to get the aliases for example but that does not work.
Any ideas?
Variable issue
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Variable issue
My guess would be that since the members parameter accepts a set of user, group, and computer objects, rather than an array of users, you need to loop through each member that is stored in your $AC variable.
Re: Variable issue
I already gave you the answer to that question.
You cannot use LIKE to match a RegEx pattern.
Also you cannot add a mailbox t]o an AD Group. Get the ADUser and add that.
See: https://social.technet.microsoft.com/Fo ... powershell
Code: Select all
$AC = Get-Mailbox -RecipientTypeDetails UserMailbox -OrganizationalUnit $OUMbx |
where {$_.DisplayName -match '^[A-C]'}
Also you cannot add a mailbox t]o an AD Group. Get the ADUser and add that.
See: https://social.technet.microsoft.com/Fo ... powershell