Private/Get-TeamViewerManagementId.ps1

function Get-TeamViewerManagementId {
    <#
    .SYNOPSIS
        Retrieves the TeamViewer Management ID from the Windows Registry.
 
    .DESCRIPTION
        The Get-TeamViewerManagementId function retrieves the TeamViewer Management ID stored in the Windows Registry.
        It accesses the specific registry key associated with TeamViewer's DeviceManagementV2 and retrieves the ManagementId value.
 
    .OUTPUTS
        String or $null.
        Returns the TeamViewer Management ID if found in the registry. If the ManagementId is not found or an error occurs,
        the function returns $null.
 
    .EXAMPLE
        $managementId = Get-TeamViewerManagementId
        Retrieves the TeamViewer Management ID from the Windows Registry and stores it in the variable $managementId.
 
    .NOTES
        Version : 1.0
    #>


    $registryPath = "HKLM:\SOFTWARE\WOW6432Node\TeamViewer\DeviceManagementV2"
    $registryValue = "ManagementId"

    try {
        $managementId = (Get-ItemProperty -Path $registryPath -Name $registryValue).$registryValue
        return $managementId
    } catch {
        Write-Warning "Unable to retrieve ManagementId from registry. Error: $_"
        return $null
    }
}