@@ -2,17 +2,28 @@ function Reset-DBODefaultSetting {
2
2
<#
3
3
. SYNOPSIS
4
4
Resets configuration entries back to default values.
5
-
5
+
6
6
. DESCRIPTION
7
7
This function creates or changes configuration values.
8
8
These can be used to provide dynamic configuration information outside the PowerShell variable system.
9
-
9
+
10
10
. PARAMETER Name
11
11
Name of the configuration entry.
12
12
13
13
. PARAMETER All
14
14
Specify if you want to reset all configuration values to their defaults.
15
15
16
+ . PARAMETER Temporary
17
+ The setting is not persisted outside the current session.
18
+ By default, settings will be remembered across all powershell sessions.
19
+
20
+ . PARAMETER Scope
21
+ Choose if the setting should be stored in current user's registry or will be shared between all users.
22
+ Allowed values: CurrentUser, AllUsers.
23
+ AllUsers will require administrative access to the computer (elevated session).
24
+
25
+ Default: CurrentUser.
26
+
16
27
. PARAMETER Confirm
17
28
Prompts to confirm certain actions
18
29
@@ -21,42 +32,51 @@ function Reset-DBODefaultSetting {
21
32
22
33
. EXAMPLE
23
34
Reset-DBODefaultSetting -Name ConnectionTimeout
24
-
35
+
25
36
Reset connection timeout setting back to default value.
26
-
37
+
27
38
. EXAMPLE
28
39
Reset-DBODefaultSetting -All
29
-
40
+
30
41
Reset all settings.
31
42
#>
32
43
[CmdletBinding (DefaultParameterSetName = " Named" , SupportsShouldProcess )]
33
44
param (
34
45
[parameter (Mandatory , ParameterSetName = ' Named' )]
35
46
[string []]$Name ,
36
47
[parameter (Mandatory , ParameterSetName = ' All' )]
37
- [switch ]$All
48
+ [switch ]$All ,
49
+ [switch ]$Temporary ,
50
+ [ValidateSet (' CurrentUser' , ' AllUsers' )]
51
+ [string ]$Scope = ' CurrentUser'
38
52
)
39
53
40
54
process {
41
55
if ($Name ) {
56
+ $settings = @ ()
42
57
foreach ($n in $Name ) {
43
- if ($PSCmdlet.ShouldProcess ($Name , " Resetting the setting back to its default value" )) {
44
- $config = Get-PSFConfig - FullName dbops.$n
45
- if ($config ) { $config.ResetValue () }
46
- else {
47
- Stop-PSFFunction - Message " Unable to find setting $n " - EnableException $true
48
- }
49
- }
58
+ $config = Get-PSFConfig - FullName dbops.$n
59
+ if ($config ) { $settings += $config }
60
+ else { Stop-PSFFunction - Message " Unable to find setting $n " - EnableException $true }
50
61
}
51
62
}
52
- elseif ($All ) {
53
- foreach ($config in Get-PSFConfig - Module dbops ) {
54
- if ($PSCmdlet.ShouldProcess ($config , " Resetting the setting back to its default value" )) {
55
- if ($config.Initialized ) {
56
- $config.ResetValue ()
57
- }
58
- else {
59
- Write-PSFMessage - Level Warning - Message " Setting $ ( $config.fullName -replace ' ^dbops\.' , ' ' ) ) was not initialized and has no default value as such"
63
+ elseif ($All ) { $settings = Get-PSFConfig - Module dbops }
64
+ $newScope = switch ($Scope ) {
65
+ ' CurrentUser' { ' UserDefault' }
66
+ ' AllUsers' { ' SystemDefault' }
67
+ }
68
+ foreach ($config in $settings ) {
69
+ $sName = $config.fullName -replace ' ^dbops\.' , ' '
70
+ if ($PSCmdlet.ShouldProcess ($config , " Resetting the setting $sName back to its default value" )) {
71
+ if ($config.Initialized ) {
72
+ $config.ResetValue ()
73
+ }
74
+ else {
75
+ Write-PSFMessage - Level Warning - Message " Setting $sName was not initialized and has no default value as such"
76
+ }
77
+ if (! $Temporary ) {
78
+ if ($PSCmdlet.ShouldProcess ($Name , " Unregistering $sName in the $newScope scope" )) {
79
+ $config | Unregister-PSFConfig - Scope $newScope
60
80
}
61
81
}
62
82
}
0 commit comments