4

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?

1
  • 1
    Expand the property - Get-MpPreference | Select-Object -expand ExclusionPath Oct 7, 2020 at 7:30

4 Answers 4

5

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)

0
4

This worked for me, listing all entries expanded:

 Get-MpPreference | Select-Object -Property ExclusionPath -ExpandProperty ExclusionPath
1

Pipe the output with the Format-Table commandlet, e.g.

Get-MpPreference | Select-Object -Property ExclusionPath | Format-Table -AutoSize

2
  • 1
    Or simply dot reference it. [(Get-MpPreference).ExclusionPath] If all you want is one property. Otherwise, the Select-Object approach as noted is more prudent.
    – postanote
    Oct 7, 2020 at 15:30
  • @spikey_richie: This solution does not work. In my case it gives ExclusionPath ------------- {%ALLUSERSPROFILE%\NTuser.pol, %SystemRoot%\System32\GroupPolicy\Machine\registry.pol, %SystemRoot%\System32\GroupPolicy\User\registry.pol, %windir%\Security\Database\*.chk...}
    – AndrePKI
    Jan 17, 2023 at 14:38
1

Use this:

$exclusions = Get-MpPreference
$exclusions.ExclusionPath
1
  • Please explain what this does and quote a reference Mar 7, 2023 at 9:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .