functions/Set-THTelemetryConfiguration.ps1

<#
.SYNOPSIS
    Configure the telemetry for a module
.DESCRIPTION
    Configure the telemetry for a module
.PARAMETER OptInVariableName
    The environment variable used to determine user-opt-in
.PARAMETER UserOptIn
    Override environment variable and opt-in
.PARAMETER StripPersonallyIdentifiableInformation
    Remove information such as the host name from telemetry
.PARAMETER IgnoreGdprCompliance
    Ignore any setting that otherwise governs if telemetry is sent
.PARAMETER ModuleName
    Auto-generated, used to select the proper configuration in case you have different modules
.PARAMETER PassThru
    Return the configuration object for further processing
.PARAMETER WhatIf
    Simulates the entire affair
.PARAMETER Confirm
    Requests confirmation that you really want to change the configuration
.EXAMPLE
    Set-THTelemetryConfiguration -IgnoreGdpr
 
    Configures the basics, but explicitly ignores any privacy regulations
#>

function Set-THTelemetryConfiguration
{
    [CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = "Low")]
    param
    (
        [Parameter()]
        [string]
        $OptInVariableName = "$(Get-CallingModule)telemetryOptIn",

        [Parameter()]
        [bool]
        $UserOptIn = $false,

        [Parameter()]
        [bool]
        $StripPersonallyIdentifiableInformation = $true,

        [Parameter()]
        [bool]
        $IgnoreGdprCompliance = $false,

        [Parameter()]
        [string]
        $ModuleName = (Get-CallingModule),

        [Parameter()]
        [switch]
        $PassThru
    )

    if ($PSCmdlet.ShouldProcess("$ModuleName telemetry", "ACTIVATE!"))
    {
        if ($null -eq (Get-PSFConfigValue -FullName TelemetryHelper.TelemetryStore)[$ModuleName])
        {
            Enable-THTelemetry -ModuleName $ModuleName
        }

        # Set object properties
        (Get-PSFConfigValue -FullName TelemetryHelper.TelemetryStore)[$ModuleName].StripPii = $StripPersonallyIdentifiableInformation
        (Get-PSFConfigValue -FullName TelemetryHelper.TelemetryStore)[$ModuleName].IgnoreGdpr = $IgnoreGdprCompliance

        # Register module-specific info
        Set-PSFConfig -Module 'TelemetryHelper' -Name "$($ModuleName).OptInVariable" -Value $OptInVariableName -Description 'The name of the environment variable used to indicate that telemetry should be sent' -PassThru | Register-PSFConfig
        Set-PSFConfig -Module 'TelemetryHelper' -Name "$($ModuleName).OptIn" -Value $false -Validation bool -Description 'Whether user opts into telemetry or not' -PassThru | Register-PSFConfig
        Set-PSFConfig -Module 'TelemetryHelper' -Name "$($ModuleName).IgnoreGdpr" -Value $false -Validation bool -Description 'Whether telemetry client should ignore user settings, e.g. if you are not bound by GDPR or other regulations' -PassThru | Register-PSFConfig
        Set-PSFConfig -Module 'TelemetryHelper' -Name "$($ModuleName).RemovePII" -VAlue $true -Validation bool -Description "Whether information like the computer name should be stripped from the data that is sent" -PassThru | Register-PSFConfig


        if ($PassThru)
        {
            (Get-PSFConfigValue -FullName TelemetryHelper.TelemetryStore)[$ModuleName]
        }
    }
}