-
Notifications
You must be signed in to change notification settings - Fork 1
/
RemoveUsersGroups.sh
55 lines (54 loc) · 2.45 KB
/
RemoveUsersGroups.sh
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
50
51
52
53
54
55
#!/bin/bash
set +x
echo "Retrieving users and groups from Genesys Cloud.."
UsersList=`gc users list -a --clientid $oauthclient_id --clientsecret $oauthclient_secret --environment $environment`
GroupsList=`gc groups list -a --clientid $oauthclient_id --clientsecret $oauthclient_secret --environment $environment`
while IFS=";" read -r column1 column2 column3 column4 column5 column6 column7 column8
do
column3=`echo "$column3" | tr '[:upper:]' '[:lower:]'`
echo "E-mail: $column3"
echo "CC SP Group: $column4"
echo "Berechtigungsgruppen: $column6"
IFS=,
read line <<<$column6
Berechtigungsgruppen=( $line )
declare -p Berechtigungsgruppen
# case sensitive version
#GroupID=`echo "${GroupsList}" | jq -r '.[] | select(.name == "'"$column4"'") | .id' | tr -d '\r'`
# case insensitive version
GroupID=`echo "${GroupsList}" | jq -r '.[] | select(.name | test("'"^$column4$"'";"i")) | .id' | tr -d '\r'`
if [ -z "$GroupID" ]
then
echo "CC SP GroupID: Group not found!"
else
echo "CC SP GroupID: $GroupID"
fi
UserID=`echo "${UsersList}" | jq -r '.[] | select(.email == "'"$column3"'") | .id' | tr -d '\r'`
if [ -z "$UserID" ]
then
echo "Missing UserID!"
else
echo "UserID: $UserID"
if [ ! -z "$GroupID" ]
then
gc groups members delete $GroupID --ids $UserID --clientid $oauthclient_id --clientsecret $oauthclient_secret --environment $environment
fi
for value in "${Berechtigungsgruppen[@]}"
do
echo "Berechtigungsgruppen: $value"
# case sensitive version
#GroupID=`gc groups list -a --clientid $oauthclient_id --clientsecret $oauthclient_secret --environment $environment | jq -r '.[] | select(.name == "'"$value"'") | .id' | tr -d '\r'`
# case insensitive version
GroupID=`gc groups list -a --clientid $oauthclient_id --clientsecret $oauthclient_secret --environment $environment | jq -r '.[] | select(.name | test("'"^$value$"'";"i")) | .id' | tr -d '\r'`
if [ -z "$GroupID" ]
then
echo "BerechtigungsgruppenID: Group not found!"
else
echo "BerechtigungsgruppenID: $GroupID"
gc groups members delete $GroupID --ids $UserID --clientid $oauthclient_id --clientsecret $oauthclient_secret --environment $environment
fi
done
echo "User $column3 removed from $column4,$column6"
fi
echo
done <<< "$(tail -n +2 RemoveUsersGroups.csv)"