Public/Get-SpecRegistryValue.ps1
function Get-specRegistryValue { <# .SYNOPSIS Retrieves a specific registry value from the specified registry path. .DESCRIPTION The Get-specRegistryValue function retrieves a specific registry value from the Windows Registry. You can specify the registry path and the name of the value you want to retrieve. If the specified registry value is found, it is returned. If the value is not found or an error occurs during the retrieval process, the function returns $null. .PARAMETER RegistryPath Specifies the registry path from which to retrieve the value. Default value is "HKLM:\SOFTWARE\WOW6432Node\TeamViewer\DeviceManagementV2". .PARAMETER RegistryValueName Specifies the name of the registry value to retrieve. Default value is "ManagementId". .EXAMPLE $managementId = Get-specRegistryValue Retrieves the registry value named "ManagementId" from the default registry path. .EXAMPLE $customId = Get-specRegistryValue -RegistryPath "HKLM:\SOFTWARE\CustomSoftware" -RegistryValueName "CustomId" Retrieves a custom registry value named "CustomId" from the specified registry path. .NOTES Author : owen.heaume Version : 1.0 #> [cmdletbinding()] param( [string]$RegistryPath = "HKLM:\SOFTWARE\WOW6432Node\TeamViewer\DeviceManagementV2", [string]$RegistryValueName = "ManagementId" ) try { write-verbose "Retrieving value [$RegistryValueName] from registry path [$RegistryPath ]" $regValue = (Get-ItemProperty -Path $RegistryPath -Name $RegistryValueName -ea stop).$registryValuename return $regValue } catch { Write-Verbose "Unable to retrieve value [$RegistryValueName] from registry. Error: $_" return 1 } } |