categories/Copilot.ps1

# Copilot category: TurnOffWindowsCopilot policy value (documented Microsoft policy).

function Get-OctaCopilotCategory {
    [CmdletBinding()]
    param()
    return [pscustomobject]@{
        Id                  = 'copilot'
        DisplayName         = 'Copilot'
        Description         = 'Disable built-in Copilot'
        RequiresElevation   = $true
        ContainsIrreversibleActions = $false
        GetActionsFunction  = 'Get-OctaCopilotActions'
        ApplyActionFunction = 'Set-OctaCopilotAction'
    }
}

function Get-OctaCopilotActions {
    [CmdletBinding()]
    param()
    $regPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsCopilot'
    $current = $null
    if (Test-Path $regPath) {
        $current = (Get-ItemProperty -Path $regPath -Name 'TurnOffWindowsCopilot' -ErrorAction SilentlyContinue).TurnOffWindowsCopilot
    }
    if ($null -ne $current -and $current -eq 1) {
        return @()
    }
    $displayCurrent = if ($null -eq $current) { '(not set)' } else { $current }
    return @(
        New-OctaAction -TargetType Registry -TargetIdentifier "$regPath|TurnOffWindowsCopilot" `
            -CurrentValue $displayCurrent -PlannedValue 1 -Reversible $true
    )
}

function Set-OctaCopilotAction {
    [CmdletBinding()]
    param([Parameter(Mandatory)]$Action)
    $keyPath, $valueName = $Action.TargetIdentifier -split '\|', 2
    if (-not (Test-Path $keyPath)) {
        New-Item -Path $keyPath -Force | Out-Null
    }
    Set-ItemProperty -Path $keyPath -Name $valueName -Value 1 -Type DWord
}