-
Notifications
You must be signed in to change notification settings - Fork 0
/
Listing 9.1.ps1
25 lines (21 loc) · 983 Bytes
/
Listing 9.1.ps1
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
##########################fetching group1 ##################
$collgroup1 = Get-ADGroup -id "group1" -Properties member |
Select-Object -ExpandProperty member |
Get-ADUser |
Select-Object -ExpandProperty samaccountname
##########################fetching group2 ##################
$collgroup2 = Get-ADGroup -id "group2" -Properties member |
Select-Object -ExpandProperty member |
Get-ADUser |
Select-Object -ExpandProperty samaccountname
####################compare two groups####################
$change = Compare-Object -ReferenceObject $collgroup1 -DifferenceObject $collgroup2
$Addition = $change |
Where-Object -FilterScript {$_.SideIndicator -eq "<="} |
Select-Object -ExpandProperty InputObject
#######adding only members that are missing in group2########
$Addition | ForEach-Object{
$sam = $_
Add-ADGroupMember -identity "group2" -Members $sam
}
##############################################################