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 } # Use the action's own PlannedValue rather than a hardcoded 1: the two always agree today, # but a hardcoded literal here means any future change to PlannedValue would be silently # ignored at apply time while the dry-run preview still promised it - every other category's # apply function already reads PlannedValue. Set-ItemProperty -Path $keyPath -Name $valueName -Value $Action.PlannedValue -Type DWord } |