How to retrieve Windows Defender exclusions by PowerShell without truncation output
Solution 1
Get-MpPreference | Select-Object -ExpandProperty ExclusionPath
-ExpandProperty
unravels the collection of ExclusionPath into separate lines, with each exclusion path on a new line.
Out-String -Width
or Format-Table -Width
doesn't help enough in case the number of items is too high, Powershell just doesn't display more than the value of $FormatEnumerationLimit
items.
So you could also set that to a higher value
$FormatEnumerationLimit=12
But then, what happens if there are more than 12 items (you could raise the number to 1500... output is still ugly)
Solution 2
This worked for me, listing all entries expanded:
Get-MpPreference | Select-Object -Property ExclusionPath -ExpandProperty ExclusionPath
Solution 3
Pipe the output with the Format-Table commandlet, e.g.
Get-MpPreference | Select-Object -Property ExclusionPath | Format-Table -AutoSize
Related videos on Youtube
Erik
Updated on September 18, 2022Comments
-
Erik over 1 year
I want to write a PowerShell Script that displays all exclusions set in Windows Defender in Windows 10. So I already found out that this can be done by calling
Get-MpPreference | Select-Object -Property ExclusionPath
Which truncates the output if there are a lot of files and folders defined.
So I tried to add
Get-MpPreference | Select-Object -Property ExclusionPath | Out-String -width 1024
Which leads to a similar output: the string gets longer, but the truncation persists, only some whitespace is added to the end:
ExclusionPath ------------- {C:\Users\Elvi\Documents\Assassin's Creed IV Black Flag, C:\Users\Elvi\Documents\Benutzerdefinierte Office-Vorlagen, C:\Users\Elvi\Documents\FHOA, C:\Users\Elvi\Documents\Gebuhrenzentrale...} PS C:\WINDOWS\system32>
So how can I prevent Powershell from truncating the output of the folders?
-
Lieven Keersmaekers over 3 yearsExpand the property -
Get-MpPreference | Select-Object -expand ExclusionPath
-
-
SimonS over 3 yearsTo improve the answer, you should explain what
-ExpandProperty
exactly does, and also you should remove the part where you critizise richie's answer and make it a comment on his answer - if you really feel that it's constructive -
postanote over 3 yearsOr simply dot reference it. [(Get-MpPreference).ExclusionPath] If all you want is one property. Otherwise, the Select-Object approach as noted is more prudent.
-
AndrePKI over 3 years@SimonS, I can't comment on other's posts as I don't have enough Reputation for that (yet)