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:

{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
    Expand the property - Get-MpPreference | Select-Object -expand ExclusionPath Oct 7 '20 at 7:30

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


But then, what happens if there are more than 12 items (you could raise the number to 1500... output is still ugly)

  • 3
    To 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
    – SimonS
    Oct 7 '20 at 8:17
  • @SimonS, I can't comment on other's posts as I don't have enough Reputation for that (yet)
    – AndrePKI
    Oct 8 '20 at 14:36

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

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

  • 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 '20 at 15:30

This worked for me, listing all entries expanded:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.