forked from Epidemic41/PS-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodify security group membership.txt
41 lines (34 loc) · 1.44 KB
/
modify security group membership.txt
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
# Store the data from csv in the $ADUsers variable
$ADUsers = Import-Csv C:\Users\winSever19\Desktop\assignment6script3.csv -Delimiter ","
# Loop through each row containing user details in the CSV file
foreach ($User in $ADUsers)
{
#Read user data from each field in each row and assign the data to a variable as below
$GroupName = $User.GroupName
$username = $User.username
$Action = $User.action
$add = "Add"
$remove= "Remove"
if ($add -eq $user.action)
{
Add-ADGroupMember `
-Identity $Groupname `
-Members $username `
# If user is created, show message.
Write-Host "The user account $username is added to $Groupname." -ForegroundColor Cyan
Read-Host -Prompt "tried to add $username"
}
if ($Remove -eq $user.action)
{
Remove-ADGroupMember -Identity $GroupName -Members $username `
# If user is created, show message.
Write-Host "The user account $username is removed from $Groupname." -ForegroundColor Cyan
Read-Host -Prompt "tried to remove $username "
}
#returns invalid $user.action
#if (($user.action -ne $Remove) -or ($user.action -ne $Add))
#{
# Write-Host "The user account $username 's action: $user.action is invalid." -ForegroundColor Cyan
#}
}
Read-Host -Prompt "Press Enter to exit"