Repository navigation
Expand file tree
/
Copy pathPopulate-OneADGroupToAnother.ps1
More file actions
49 lines (33 loc) · 2.24 KB
/
Copy pathPopulate-OneADGroupToAnother.ps1
File metadata and controls
49 lines (33 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<#
########################################################################################################################################################################
# Script: Remove-NestedGroups.ps1
# Author: Jason Dance
# Created Date: Jan 28, 2020
# Last Updated: Dec 11, 2020
# Description: This script can be used to transfer the content of one group to another.
# Pick a group from the list presented, and the script will pull the users from the source group and add them to the target group.
# Usage: Just run the script in Powershell or Powershell ISE. No arguments or switches are needed, just run the script and answer the prompts.
########################################################################################################################################################################
#>
import-module activedirectory
If (!(Get-Module ActiveDirectory)){
write-host("Not able to load the Active Directory powershell module (is it installed?) https://theitbros.com/install-and-import-powershell-active-directory-module") -BackgroundColor DarkRed
break}
$GroupCategorySource= (("Distribution","Security") | Out-GridView -Title "Select a group type for the source:" -OutputMode Single)
If (!$GroupCategorySource){
write-host("No type value selected") -BackgroundColor DarkRed
break}
$FromGroup = (Get-ADGroup -Filter 'GroupCategory -eq $GroupCategorySource') | sort | Out-GridView -Title "Select a group to pull users from:" -OutputMode Multiple
$GroupCategoryTarget= (("Distribution","Security") | Out-GridView -Title "Select a group type for the target:" -OutputMode Single)
If (!$GroupCategoryTarget){
write-host("No type value selected") -BackgroundColor DarkRed
break}
$ToGroup = (Get-ADGroup -Filter 'GroupCategory -eq $GroupCategoryTarget') | sort | Out-GridView -Title "Select a target group:" -OutputMode Multiple
If (!$ToGroup -or !$FromGroup){
write-host("No group value selected") -BackgroundColor DarkRed
break}
$users = Get-ADGroupMember -Id $FromGroup | select @{Expression={$FromGroup};Label="Group Name"},SamAccountName
foreach ($user in $users){
write-host $user
Add-ADGroupMember -Identity $ToGroup -Members $user
}