-
Notifications
You must be signed in to change notification settings - Fork 1
/
Get-SimulatedModifications.ps1
149 lines (116 loc) · 4.95 KB
/
Get-SimulatedModifications.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
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<#
* modifications.txt contains all the modifications in the log output
* each is numbered
E.g. of the start of that file:
Modify user 1: "[email protected]"
Change stored unique identifier to "RyaOeU9uTEaOQwuAyCBTtg"
Modify user 2: "[email protected]"
Change stored unique identifier to "2QWj1qwO9ES5oHYiyMSaSw"
. . .
#>
$file = Get-Content .\modifications.txt
$currentUser = [PSCustomObject]@{
Account = ""
Actions = [ordered]@{
NameTo = ""
GivenNameTo = ""
FamilyNameTo = ""
SuspendUser = ""
ReasonForSuspend = ""
UpdateKey = ""
}
}
$actionsPer = [ordered]@{}
$modifications = [PSCustomObject]@()
for ($i = 0; $i -lt $file.Count; $i++)
{
if ($file[$i])
{
$indentation = ("$($file[$i])".Split("`t")).Count - 1
if ($indentation -eq 0)
{
$currentUser.Account = "$($file[$i])".Split(' ')[3]
#Write-Host "SET ACCOUNT TO $($currentUser.Account)" -ForegroundColor Yellow
}
elseif ($indentation -eq 1)
{
$wordsInAction = "$($file[$i])".Split(' ')
# if action is to suspend
if ($wordsInAction[0] -eq "`tSuspend")
{
$actionsPer["SuspendUser"] = "TRUE"
$actionsPer["ReasonForSuspend"] = "$("$($file[$i + 1])".Split("`t")[1])"
++$i
continue
}
elseif ($wordsInAction[0] -eq "`tRestore")
{
$actionsPer["RestoreUser"] = "TRUE"
}
# if action is to change a name or 'org'
elseif ($wordsInAction[0] -eq "`tChange")
{
if ($wordsInAction[1] -eq "org")
{
$actionsPer["NameTo"] = "$($wordsInAction[3]) $($wordsInAction[4])"
}
elseif ($wordsInAction[1] -eq "given")
{
$actionsPer["GivenNameTo"] = "$($wordsInAction[4])"
}
elseif ($wordsInAction[1] -eq "family")
{
$actionsPer["FamilyNameTo"] = "$($wordsInAction[4])"
}
elseif ($wordsInAction[1] -eq "stored")
{
$actionsPer["UpdateKey"] = "$($wordsInAction[6])"
}
else
{
Write-Host "$($wordsInAction[1])"
}
}
else
{
Write-Host $file[$i] -ForegroundColor Red
}
}
}
else
{
# Add previous object to list
$currentUser.Actions = $actionsPer
#Write-Host "CURRENTUSER ACCOUNT: $($currentUser.Account)" -ForegroundColor Cyan
#Write-Host " ACTIONS: $($currentUser.Actions.Keys)`n" -ForegroundColor Cyan
$modifications += $currentUser
# Reset current user object
#Write-Host "RESETTING CURRENTUSER OBJECT" -ForegroundColor Yellow
$currentUser = [PSCustomObject]@{
Account = ""
Actions = [ordered]@{
NameTo = ""
GivenNameTo = ""
FamilyNameTo = ""
SuspendUser = ""
ReasonForSuspend = ""
RestoreUser = ""
UpdateKey = ""
}
}
$actionsPer = [ordered]@{}
}
}
$justKeyChange = $modifications | Where-Object {$_.Actions.Count -eq 1 -and ($_.Actions).GetEnumerator().Name -eq "UpdateKey"}
$twoActions = $modifications | Where-Object {$_.Actions.Count -eq 2}
$keyAndCNChange = $twoActions | Where-Object {($_.Actions).GetEnumerator().Name -contains "NameTo"}
$suspended = $twoActions | Where-Object {($_.Actions).GetEnumerator().Name -contains "SuspendUser"}
$restored = $modifications | Where-Object {($_.Actions).GetEnumerator().Name -contains "RestoreUser"}
$nameChange = $modifications | Where-Object {($_.Actions).GetEnumerator().Name -contains "GivenNameTo" -or ($_.Actions).GetEnumerator().Name -contains "FamilyNameTo"}
Remove-Item .\mod-*
$keyAndCNChange | ForEach-Object {$line = "$($_.Account)".Split('"')[1]; Write-Output "$line" | Out-File -Append .\mod-name-and-key-updates.txt}
$justKeyChange | ForEach-Object {$line = "$($_.Account)".Split('"')[1]; Write-Output "$line" | Out-File -Append .\mod-just-key-updates.txt}
$nameChange | ForEach-Object {$line = "$($_.Account)".Split('"')[1]; Write-Output "$line" | Out-File -Append .\mod-name-changes.txt}
$restored | ForEach-Object {$line = "$($_.Account)".Split('"')[1]; Write-Output "$line" | Out-File -Append .\mod-restored-users.txt}
$suspended | ForEach-Object {$line = "$($_.Account)".Split('"')[1]; Write-Output "$line" | Out-File -Append .\mod-suspensions.txt}
Write-Host "NameAndKeyChange: $($keyAndCNChange.Count)`nJustKeyChange: $($justKeyChange.Count)`nNameChange: $($nameChange.Count)`nRestored: $($restored.Count)`nSuspended: $($suspended.Count)" -ForegroundColor Yellow