Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset-DbatoolsConfig - add supportshoudlprocess #5499

Merged
merged 1 commit into from
May 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions functions/configuration/Reset-DbatoolsConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,75 +3,75 @@ function Reset-DbatoolsConfig
<#
.SYNOPSIS
Reverts a configuration item to its default value.

.DESCRIPTION
This command can be used to revert a configuration item to the value it was initialized with.
Generally, this amounts to reverting it to its default value.

In order for a reset to be possible, two conditions must be met:
- The setting must have been initialized.
- The setting cannot have been enforced by policy.

.PARAMETER ConfigurationItem
A configuration object as returned by Get-DbatoolsConfig.

.PARAMETER FullName
The full name of the setting to reset, offering the maximum of precision.

.PARAMETER Module
The name of the module, from which configurations should be reset.
Used in conjunction with the -Name parameter to filter a specific set of items.

.PARAMETER Name
Used in conjunction with the -Module parameter to select which settings to reset using wildcard comparison.

.PARAMETER EnableException
This parameters disables user-friendly warnings and enables the throwing of exceptions.
This is less user friendly, but allows catching exceptions in calling scripts.

.PARAMETER Confirm
If this switch is enabled, you will be prompted for confirmation before executing any operations that change state.

.PARAMETER WhatIf
If this switch is enabled, no actions are performed but informational messages will be displayed that explain what would happen if the command were to run.

.EXAMPLE
PS C:\> Reset-DbatoolsConfig -Module MyModule

Resets all configuration items of the MyModule to default.

.EXAMPLE
PS C:\> Get-DbatoolsConfig | Reset-DbatoolsConfig

Resets ALL configuration items to default.

.EXAMPLE
PS C:\> Reset-DbatoolsConfig -FullName MyModule.Group.Setting1

Resets the configuration item named 'MyModule.Group.Setting1'.
#>
[CmdletBinding(DefaultParameterSetName = 'Pipeline')]
[CmdletBinding(DefaultParameterSetName = 'Pipeline', SupportsShouldProcess, ConfirmImpact='Low')]
param (
[Parameter(ValueFromPipeline = $true, ParameterSetName = 'Pipeline')]
[Sqlcollaborative.Dbatools.Configuration.Config[]]
$ConfigurationItem,

[Parameter(ValueFromPipeline = $true, ParameterSetName = 'Pipeline')]
[string[]]
$FullName,

[Parameter(Mandatory = $true, ParameterSetName = 'Module')]
[string]
$Module,

[Parameter(ParameterSetName = 'Module')]
[string]
$Name = "*",

[switch]
$EnableException
)

process
{
#region By configuration Item
Expand All @@ -84,14 +84,14 @@ function Reset-DbatoolsConfig
}
}
#endregion By configuration Item

#region By FullName
foreach ($nameItem in $FullName)
{
# The configuration items themselves can be cast to string, so they need to be filtered out,
# otherwise on bind they would execute for this code-path as well.
if ($nameItem -ceq "Sqlcollaborative.Dbatools.Configuration.Config") { continue }

foreach ($item in (Get-DbatoolsConfig -FullName $nameItem))
{
if ($PSCmdlet.ShouldProcess($item.FullName, 'Reset to default value'))
Expand Down