Link to home
Start Free TrialLog in
Avatar of Ron Shorts
Ron ShortsFlag for United States of America

asked on

Foreach statement to copy unified group members

Looking for help in getting input from a .csv file for copying group members from one group to another.  Both are Unified groups.

This code works for a single group to group copy:
$List = Get-UnifiedGroupLinks -Identity "Group1" -LinkType Members | Select-Object -expandproperty name
Add-UnifiedGroupLinks -Identity "Group2" -LinkType Members -Links $List

Open in new window


This is what I setup in for foreach:

$Groups = Import-Csv -Path .\GroupInput.csv
foreach ($Group in $Groups) {
    $List = Get-UnifiedGroupLinks -Identity $_.SourceGroup -LinkType Members | Select-Object -expandproperty name
    Add-UnifiedGroupLinks -Identity $_.TargetGroup -LinkType Members -Links $List
}

Open in new window


Error I'm getting is:
Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Get-UnifiedGroupLinks], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-UnifiedGroupLinks
    + PSComputerName        : outlook.office365.com

GroupInput.csv:
SourceGroup,TargetGroup
Group1,Group2
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial