diff --git a/Microsoft/Disable_Cortana.ps1 b/Microsoft/Disable_Cortana.ps1 new file mode 100644 index 0000000..b521d60 --- /dev/null +++ b/Microsoft/Disable_Cortana.ps1 @@ -0,0 +1,62 @@ +# Script by Timur@0x01337.com +# Date: 2023-11-24 +<# +.DESCRIPTION +Disables Cortana + +Requires administrator privileges. + +.PARAMETER help +Displays a detailed usage description of this script. + +.EXAMPLE +PS> .\Disable-Cortana.ps1 + +.EXAMPLE +PS> .\Disable-Cortana.ps1 -help +#> + +# Getting command line parameters +param ( + [parameter(Mandatory = $false)][switch]$help +) + +$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()) +$isAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) +if (!$isAdmin) { + Write-Error "This script requires administrator privileges" + exit 1 +} + +# Writing help message +if ($help) { + get-help $MyInvocation.MyCommand.Path -Full + exit 0 +} + +$registryKeyPath = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\Windows Search' +$propertyName = 'AllowCortana' + +if (!(Test-Path $registryKeyPath)) { + Write-Host "Create registry key path ($registryKeyPath)" + New-Item -Path $registryKeyPath -Force +} + +try { + Get-ItemProperty -Path $registryKeyPath -Name $propertyName -ErrorAction Stop | Out-Null +} +catch { + Write-Host "Create property ($propertyName) in ($registryKeyPath)" + New-ItemProperty -Path $registryKeyPath -Name $propertyName -PropertyType DWORD -Value '0' +} + +try { + Set-ItemProperty -Path $registryKeyPath -Name $propertyName -Value '0' +} +catch { + Write-Error $_ + exit 1 +} + +Write-Host "Cortana is disabled" +exit 0