Nope, doesn’t seem to allow me to do that. Seems Microsoft doesn’t want you doing this this way.
I wrote this:
$PathsToExclude = (
"C:\Test01",
"C:\Test02",
"C:\Test03"
)
$RegPath = "HKLM:\SOFTWARE\Microsoft\Windows Defender\Exclusions\Paths"
ForEach($Path in $PathsToExclude) {
New-ItemProperty -Path $RegPath -Name $Path -Value 0 -Force
}
Ran with admin rights, but got this error:
New-ItemProperty : Requested registry access is not allowed.
At C:\Users\support\Documents\ExceptionTest.ps1:10 char:5
+ New-ItemProperty -Path $RegPath -Name $Path -Value 0 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...xclusions\Paths:String) [New-ItemProperty], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.NewItemPropertyCommand
New-ItemProperty : Requested registry access is not allowed.
At C:\Users\support\Documents\ExceptionTest.ps1:10 char:5
+ New-ItemProperty -Path $RegPath -Name $Path -Value 0 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...xclusions\Paths:String) [New-ItemProperty], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.NewItemPropertyCommand
New-ItemProperty : Requested registry access is not allowed.
At C:\Users\support\Documents\ExceptionTest.ps1:10 char:5
+ New-ItemProperty -Path $RegPath -Name $Path -Value 0 -Force
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (HKEY_LOCAL_MACH...xclusions\Paths:String) [New-ItemProperty], SecurityException
+ FullyQualifiedErrorId : System.Security.SecurityException,Microsoft.PowerShell.Commands.NewItemPropertyCommand
99% sure that GPO could do this.
SYSTEM has Full Control permission to this path though, so not sure why it didn’t work from Snapin.