-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from webmd-health-services/feature/mirate-from-…
…carbon Migrating from Carbon
- Loading branch information
Showing
17 changed files
with
1,037 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
# Carbon.Registry Changelog | ||
|
||
## 1.0.0 | ||
|
||
> Released 16 Aug 2023 | ||
Migrated Carbon registry functions. | ||
|
||
### Upgrade Instructions | ||
|
||
All functions now require using the `C` prefix. | ||
|
||
* Replace usages of `Get-RegistryKeyValue` with `Get-CRegistryKeyValue`. | ||
* Replace usages of `Remove-RegistryKeyValue` with `Remove-CRegistryKeyValue`. | ||
* Replace usages of `Set-RegistryKeyValue` with `Set-CRegistryKeyValue`. | ||
* Replace usages of `Test-RegistryKeyValue` with `Test-CRegistryKeyValue`. | ||
* Replace usages of `Install-RegistryKey` with `Install-CRegistryKey`. | ||
|
||
Remove usages of the `Quiet` switch from usages of `Set-CRegistryKeyValue`. That switch was removed. | ||
|
||
### Changed | ||
|
||
* Replaced verbose-level messages with information-level messages in `Install-CRegistryKey`, `Remove-CRegistryKeyValue`, | ||
and `Set-CRegistryKeyValue` when saving changes. | ||
* `Set-CRegistryKeyValue` accepts `$null` as the value of a multi-line string, which sets the value to an empty list. | ||
|
||
### Fixed | ||
|
||
* `Set-CRegistryKeyValue` fails to set multiline string values to an empty list. | ||
* `Set-CRegistryKeyValue` sets the value of a multiline string even if the value hasn't changed. | ||
|
||
### Removed | ||
|
||
* `Get-RegistryKeyValue` (use `Get-CRegistryKeyValue` instead). | ||
* `Remove-RegistryKeyValue` (use `Remove-CRegistryKeyValue` instead). | ||
* `Set-RegistryKeyValue` (use `Set-CRegistryKeyValue` instead). | ||
* `Test-RegistryKeyValue` (use `Test-CRegistryKeyValue` instead). | ||
* `Install-RegistryKey` (use `Install-CRegistryKey` instead). | ||
* Parameter `Quiet` from `Set-CRegistryKeyValue`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
function Get-CRegistryKeyValue | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Gets the value from a registry key. | ||
.DESCRIPTION | ||
PowerShell's `Get-ItemProperty` cmdlet is a pain to use. It doesn't actually return an object representing a | ||
registry key's value, but some other weird object that requires painful gyrations to get values from. This function | ||
returns just the value of a key. | ||
.EXAMPLE | ||
Get-CRegistryKeyValue -Path 'hklm:\Software\Carbon\Test' -Name 'Title' | ||
Returns the value of the 'hklm:\Software\Carbon\Test' key's `Title` value. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
# The path to the registry key where the value should be set. Will be created if it doesn't exist. | ||
[Parameter(Mandatory)] | ||
[String] $Path, | ||
|
||
# The name of the value being set. | ||
[Parameter(Mandatory)] | ||
[String] $Name | ||
) | ||
|
||
Set-StrictMode -Version 'Latest' | ||
Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState | ||
|
||
if (-not (Test-CRegistryKeyValue -Path $Path -Name $Name)) | ||
{ | ||
return $null | ||
} | ||
|
||
$itemProperties = Get-ItemProperty -Path $Path -Name * | ||
$value = $itemProperties.$Name | ||
Write-Debug -Message ('[{0}@{1}: {2} -is {3}' -f $Path,$Name,$value,$value.GetType()) | ||
return $value | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
function Install-CRegistryKey | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Creates a registry key. If it already exists, does nothing. | ||
.DESCRIPTION | ||
Given the path to a registry key, creates the key and all its parents. If the key already exists, nothing happens. | ||
.EXAMPLE | ||
Install-CRegistryKey -Path 'hklm:\Software\Carbon\Test' | ||
Creates the `hklm:\Software\Carbon\Temp` registry key if it doesn't already exist. | ||
#> | ||
[CmdletBinding(SupportsShouldPRocess)] | ||
param( | ||
# The path to the registry key to create. | ||
[Parameter(Mandatory)] | ||
[String] $Path | ||
) | ||
|
||
Set-StrictMode -Version 'Latest' | ||
Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState | ||
|
||
if (-not (Test-Path -Path $Path -PathType Container)) | ||
{ | ||
Write-Information " + ${Path}" | ||
New-Item -Path $Path -ItemType RegistryKey -Force | Out-String | Write-Verbose | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
function Remove-CRegistryKeyValue | ||
{ | ||
<# | ||
.SYNOPSIS | ||
Removes a value from a registry key, if it exists. | ||
.DESCRIPTION | ||
If the given key doesn't exist, nothing happens. | ||
.EXAMPLE | ||
Remove-CRegistryKeyValue -Path hklm:\Software\Carbon\Test -Name 'InstallPath' | ||
Removes the `InstallPath` value from the `hklm:\Software\Carbon\Test` registry key. | ||
#> | ||
[CmdletBinding(SupportsShouldProcess)] | ||
param( | ||
# The path to the registry key where the value should be removed. | ||
[Parameter(Mandatory)] | ||
[String] $Path, | ||
|
||
# The name of the value to remove. | ||
[Parameter(Mandatory)] | ||
[String] $Name | ||
) | ||
|
||
Set-StrictMode -Version 'Latest' | ||
Use-CallerPreference -Cmdlet $PSCmdlet -Session $ExecutionContext.SessionState | ||
|
||
if (-not (Test-CRegistryKeyValue -Path $Path -Name $Name)) | ||
{ | ||
return | ||
} | ||
|
||
if (-not $PSCmdlet.ShouldProcess(("Item: ${Path} Property: ${Name}"), 'Remove Property')) | ||
{ | ||
return | ||
} | ||
|
||
Write-Information " ${Path} - ${Name}" | ||
Remove-ItemProperty -Path $Path -Name $Name | ||
} |
Oops, something went wrong.