forked from Gerenios/AADInternals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Configuration.ps1
134 lines (115 loc) · 3.02 KB
/
Configuration.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
# Load the settings from config.json
# May 29th 2023
function Read-Configuration
{
<#
.SYNOPSIS
Loads AADInternals settings
.DESCRIPTION
Loads AADInternals settings from config.json. All changes made after loading AADInternals module will be lost.
.Example
PS C:\>Read-AADIntConfiguration
#>
[cmdletbinding()]
param()
Process
{
# Clear the settings
$Script:config = @{}
# ConvertFrom-Json -AsHashtable not supported in PowerShell 5.1
$configObject = Get-Content -Path "$PSScriptRoot\config.json" | ConvertFrom-Json
foreach($property in $configObject.PSObject.Properties)
{
$Script:config[$property.Name] = $property.Value
}
}
}
# Save the settings to config.json
# May 29th 2023
function Save-Configuration
{
<#
.SYNOPSIS
Saves AADInternals settings
.DESCRIPTION
Saves the current AADInternals settings to config.json. Settings will be loaded when AADInternals module is loaded.
.Example
PS C:\>Save-AADIntConfiguration
#>
[cmdletbinding()]
param()
Process
{
$Script:config | ConvertTo-Json | Set-Content -Path "$PSScriptRoot\config.json"
Write-Host "Settings saved."
}
}
# Shows the configuration
# May 29th 2023
function Get-Configuration
{
<#
.SYNOPSIS
Shows AADInternals settings
.DESCRIPTION
Shows AADInternals settings
.Example
PS C:\>Get-AADIntSettings
Name Value
---- -----
SecurityProtocol Tls12
User-Agent AADInternals
#>
[cmdletbinding()]
param()
Process
{
$Script:config
}
}
# Get AADInternals setting
# May 29th 2023
function Get-Setting
{
[cmdletbinding()]
param(
[parameter(Mandatory=$true, ValueFromPipeline)]
[string]$Setting
)
Process
{
return $Script:config[$Setting]
}
}
# Sets AADInternals setting value
# May 29th 2023
function Set-Setting
{
<#
.SYNOPSIS
Sets the given setting with given value
.DESCRIPTION
Sets the given setting with given value. To persist, use Save-AADIntConfiguration after setting the value.
.Parameter Setting
Name of the setting to be set
.Parameter Value
Value of the setting
.Example
PS C:\>Set-AADIntSetting -Setting "User-Agent" -Value "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
.Example
PS C:\>Set-AADIntSetting -Setting "User-Agent" -Value "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
PS C:\>Save-AADIntConfiguration
Settings saved.
#>
[cmdletbinding()]
param(
[parameter(Mandatory=$true, ValueFromPipeline, Position=0)]
[string]$Setting,
[parameter(Mandatory=$true, ValueFromPipeline, Position=1)]
[PSObject]$Value
)
Process
{
$Script:config[$Setting] = $value
}
}