'how to block .exe files in windows using powershell commands?

I want to block some of the downloaded .exe file in windows using PowerShell .Manually I done by this process https://www.wikihow.com/Block-an-Application-or-.EXE-from-Running-in-Windows but I need to do using PowerShell.



Solution 1:[1]

I have three one liners for you

1st creates DisallowRun key

New-ItemProperty -path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\explorer\" -Name "DisallowRun" -PropertyType DWord -Value "1"

2nd creates DisallowRun container

New-item -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\explorer\" -Name "DisallowRun"

3rd creates key for the .exe file you want to block. Variable added for convinience

$1 = "test.exe"
New-ItemProperty -path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\explorer\DisallowRun" -Name "1" -PropertyType String -Value "$1" 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nawad-sama