ps/Modules/Alkami.PowerShell.Configuration/Public/New-RegistryKey.ps1

38 lines
1015 B
PowerShell
Raw Permalink Normal View History

2023-05-30 22:51:22 -07:00
function New-RegistryKey {
<#
.SYNOPSIS
Create a new registry key
.DESCRIPTION
Creates key givin a path, does not create property for key.
.EXAMPLE
New-RegistryKey -regKey HKCU:\Environment\foo -Verbose
#>
[cmdletbinding()]
param (
$RegKey
)
$logLead = Get-LogLeadName
$regKeyParent = Split-Path -Path $RegKey -Parent
$regKeyName = Split-Path -Path $RegKey -Leaf
try {
Write-Verbose "$logLead : Testing for key's existance $RegKey"
if (!(Test-RegistryKey $RegKey)) {
Write-Verbose "$logLead : Creating Registery Key $RegKey"
$regKeyResult = New-Item -Path $regKeyParent -Name $regKeyName
Write-Host "$logLead : Registry key created."
} else {
throw "$logLead : Registry key already exists."
}
} catch [System.Management.Automation.PSArgumentException] {
Write-Warning "$logLead : $RegKey exists."
} catch {
Write-Warning "$loglead : $_"
}
return $regKeyResult
}