AL/Set-AppSourceCopKeyValue.ps1

function Set-AppSourceCopKeyValue {
    Param(
        [Parameter(Mandatory=$false)]
        [string]$SourcePath = (Get-Location),
        [Parameter(Mandatory=$true)]
        [string]$KeyName,
        [Parameter(Mandatory=$false)]
        [string]$KeyValue
    )

    $JsonContent = Get-Content (Join-Path $SourcePath 'AppSourceCop.json') -Raw
    $Json = ConvertFrom-Json $JsonContent

    if ($KeyValue -eq '') {
        $Json.PSObject.Properties.Remove($KeyName)
    }
    else {
        if ($null -eq $Json.PSObject.Properties.Item($KeyName)) {
            $Json.PSObject.Properties.Add((New-Object System.Management.Automation.PSNoteProperty($KeyName,$KeyValue)))
        }
        else {
            $Json.PSObject.Properties.Item($KeyName).Value = $KeyValue
        }
    }
    
    $JsonContent = ConvertTo-Json $Json

    Set-Content -Path (Join-Path $SourcePath 'AppSourceCop.json') -Value $JsonContent
}

Export-ModuleMember -Function Set-AppSourceCopKeyValue