PowerShell/Microsoft/Hide_non-critical_notifications.ps1

65 lines
1.6 KiB
PowerShell

# Script by Timur@0x01337.com
# Date: 2023-11-24
<#
.DESCRIPTION
Hides non-critical Windows notifications.
Requires administrator privileges and restart.
.PARAMETER help
Displays a detailed usage description of this script.
.EXAMPLE
PS> .\Hide-Non-Critical-Notifications.ps1
.EXAMPLE
PS> .\Hide-Non-Critical-Notifications.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
}
$regLocation = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows Defender Security Center\Notifications'
$regKey = 'DisableEnhancedNotifications'
if (!(Test-Path $regLocation)) {
Write-Host "Creating registry key path ($regLocation)"
New-Item -Path $regLocation -Force
}
try {
Get-ItemProperty -Path $regLocation -Name $regKey -ErrorAction Stop | Out-Null
}
catch {
Write-Host "Creating property ($regKey) in ($regLocation)"
New-ItemProperty -Path $regLocation -Name $regKey -PropertyType DWORD -Value '1'
}
try {
Set-ItemProperty -Path $regLocation -Name $regKey -Value '1'
}
catch {
Write-Error $_
exit 1
}
Write-Host "Non-critical Windows notifications now will be hidden. Please restart in order for the changes to take effect"
exit 0