#script to disable copilot in windows
function Get-CurrentUser() {
try {
$currentUser=Get-CimInstance -ClassName Win32_ComputerSystem | Select-Object -ExpandProperty UserName
if (-NOT[string]::IsNullOrEmpty($currentUser)) {
$currentUser=$currentUser.Split("\")[1]
Write-Output $currentUser
}
else {
Write-Host "Script cannot be executed->no user is currently active on the system"
Write-Output "0"
}
}
catch {
Write-Host "Error occured while getting current user -> ",$_.Exception.Message
Write-Output "0"
}
}
function Get-UserSID([string]$fCurrentUser) {
try {
$user = New-Object System.Security.Principal.NTAccount($fcurrentUser)
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier])
if (-NOT[string]::IsNullOrEmpty($sid)) {
Write-Output $sid.Value
}
else {
Write-Host "SID is empty!"
Write-Output "0"
}
}
catch {
Write-Host "Error occured while getting user sid -> ",$_.Exception.Message
Write-Output "0"
}
}
Write-Host "--------------starting script execution--------------"
$currentUser = Get-CurrentUser
if ($currentUser -ne "0"){
$currentUserSID = Get-UserSID $currentUser
if ($currentUserSID -ne "0"){
$userRegistryPath = "Registry::HKEY_USERS\$($currentUserSID)\Software\Policies\Microsoft\Windows\WindowsCopilot" #"HKCU\Software\Policies\Microsoft\Windows\WindowsCopilot".
if(Test-Path -path "$userRegistryPath")
{
Write-host "Setting up registry key"
}
else {
New-Item -Path "$userRegistryPath"
Write-host "Setting up registry key"
}
Set-ItemProperty -Path $userRegistryPath -Name TurnOffWindowsCopilot -Value 1 #Enable=0/Disable=1.
}
}
Write-Host "--------------Copilot configured for user $currentUser. Restart Device --------------"