diff --git a/src/Public/Remove-RegistryKey.ps1 b/src/Public/Remove-RegistryKey.ps1 new file mode 100644 index 0000000..87aa160 --- /dev/null +++ b/src/Public/Remove-RegistryKey.ps1 @@ -0,0 +1,40 @@ +<# +.SYNOPSIS + Removes a complete key from the registry +.DESCRIPTION + Removes a complete key from the registry and returns true or false if successfull or not +.EXAMPLE + PS C:\> Remove-RegistryKey -Path "HKLM:\testkey" + Removes the Key HKLM:\testkey +.NOTES + General notes +.OUTPUTS + Boolean value which corresponds to the outcome +#> +function Remove-RegistryKey +{ + param ( + # the path to the value + [Parameter()] + [string] + $KeyPath, + + # if should be logged to LogAnalytics + [Parameter()] + [switch] + $Log + ) + $PSDefaultParameterValues = $Global:PSDefaultParameterValues + If(Test-Path $KeyPath) + { + try + { + Remove-Item -Path $KeyPath -ErrorAction Stop -Recurse -Force + If($Log) { Send-ToLogAnalytics -message "Removed $KeyPath." } + } + catch + { + If($Log) { Send-ToLogAnalytics -message "Could not remove $KeyPath. $($_.Exception) $($_.ErrorDetails)" } + } + } +} \ No newline at end of file diff --git a/src/Public/Remove-RegistryValue.ps1 b/src/Public/Remove-RegistryValue.ps1 index 0fa39de..5c011f1 100644 --- a/src/Public/Remove-RegistryValue.ps1 +++ b/src/Public/Remove-RegistryValue.ps1 @@ -30,18 +30,18 @@ function Remove-RegistryValue $Log ) $PSDefaultParameterValues = $Global:PSDefaultParameterValues - If(Test-Path $RegistryPath) + If(Test-Path $Path) { - If(Test-RegistryValue -Path $RegistryPath -Value $RegistryValue) + If(Test-RegistryValue -Path $Path -Value $RegistryValue) { try { - Remove-ItemProperty -Path $RegistryPath -Name $RegistryValue -ErrorAction Stop - If($Log) { Send-ToLogAnalytics -message "Removed $RegistryValue in path $RegistryPath." } + Remove-ItemProperty -Path $Path -Name $RegistryValue -ErrorAction Stop + If($Log) { Send-ToLogAnalytics -message "Removed $Path in path $RegistryPath." } } catch { - If($Log) { Send-ToLogAnalytics -message "Could not remove $RegistryValue in path $RegistryPath. $($_.Exception) $($_.ErrorDetails)" } + If($Log) { Send-ToLogAnalytics -message "Could not remove $Path in path $RegistryPath. $($_.Exception) $($_.ErrorDetails)" } } } } diff --git a/src/wrt.helpers.psd1 b/src/wrt.helpers.psd1 index 258dc0d..778a7a3 100644 --- a/src/wrt.helpers.psd1 +++ b/src/wrt.helpers.psd1 @@ -12,7 +12,8 @@ RootModule = 'wrt.helpers.psm1' # Version number of this module. - ModuleVersion = '1.1.0' + + ModuleVersion = '1.0.3' # Supported PSEditions CompatiblePSEditions = 'Core', 'Desktop'