Created
August 16, 2021 19:53
-
-
Save machv/fa2c93871dae1dba7ea28c5df0e25d81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Connect-AzAccount | |
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | |
#region Source group | |
$sourceGroupName = [Microsoft.VisualBasic.Interaction]::InputBox('Zadejte název zdrojové Azure AD skupiny pro načtení členů:', 'Zdrojová skupina') | |
if(-not $sourceGroupName) { | |
Write-Host -ForegroundColor Yellow "Je potřeba zadat jméno skupiny" | |
return | |
} | |
$sourceGroup = Get-AzADGroup -DisplayNameStartsWith $sourceGroupName | |
if ( ($sourceGroup | Measure-Object).Count -gt 1) { | |
$sourceGroup = $sourceGroup | Out-GridView -Title "Kterou skupinu použít?" -OutputMode Single | |
} | |
If(-not $sourceGroup) { | |
Write-Warning "NEpovedlo se najít žádnou skupinu začínající na $sourceGroupName" | |
return | |
} | |
Write-Host -ForegroundColor Gray "Using $($sourceGroup.DisplayName) (ID $($sourceGroup.Id) as a source" | |
#endregion | |
#region Destination | |
$destinationGroupName = [Microsoft.VisualBasic.Interaction]::InputBox('Zadejte název cílové Azure AD skupiny pro překopírování členů:', 'Cílová skupina') | |
if(-not $destinationGroupName) { | |
Write-Host -ForegroundColor Yellow "Je potřeba zadat jméno skupiny" | |
return | |
} | |
$destinationGroup = Get-AzADGroup -DisplayNameStartsWith $destinationGroupName | |
if ( ($destinationGroup | Measure-Object).Count -gt 1) { | |
$destinationGroup = $destinationGroup | Out-GridView -Title "Kterou skupinu použít?" -OutputMode Single | |
} | |
If(-not $destinationGroup) { | |
Write-Warning "NEpovedlo se najít žádnou skupinu začínající na $sourceGroupName" | |
return | |
} | |
Write-Host -ForegroundColor Gray "Using $($destinationGroup.DisplayName) (ID $($destinationGroup.Id) as a destination" | |
#endregion | |
#region Copy | |
$members = Get-AzADGroupMember -GroupObjectId $sourceGroup.Id | |
$filteredMembers = $members | Out-GridView -Title "Vyberte, které členy přenést" -OutputMode Multiple | |
foreach($member in $filteredMembers) { | |
Write-Host "[+] Adding $($member.DisplayName)" | |
Add-AzADGroupMember -MemberObjectId $member.Id -TargetGroupObjectId $destinationGroup.Id -ErrorAction SilentlyContinue | |
} | |
#endregion |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment