# Get exclusions from file PowerShell

**URL:** <https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826>\
**Category:** PowerShell Help\
**Created:** [August 19, 2020, 9:36am UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826 "2020-08-19T09:36:37Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![clementb](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@clementb](https://forums.powershell.org/u/clementb)\
**Post date:** [August 19, 2020, 9:36am UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/1 "2020-08-19T09:36:37Z")

</div>

Hello there,  
I just want to set extension exclusion from file (7zip utilization). If I write this command, it’s work perfectly :  
`7zip a -t7z -m0=lzma2 -mx=9 -mmt=on -mhe=on -p"$Password" $Target $itemsToSave ‘-xr!.lck’ '-xr!.log’`  
But, if I want to take exclusions from file in PowerShell, It doesn’t work :

```
$exclusion = get-content -Path "conf\exclusion.txt"
7zip a -t7z -m0=lzma2 -mx=9 -mmt=on -mhe=on -p"$Password" $Target $itemsToSave $exclusion
```

Here the result of file (exactly the same output with `write-host $exclusion`) :  
`‘-xr!.lck’ '-xr!.log’`  
Someone can help me ?

Thanks,  
Clement.

---

<div class="post-metadata">

**Author:** ![adminofthings](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@adminofthings](https://forums.powershell.org/u/adminofthings)\
**Post date:** [August 19, 2020, 8:31pm UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/2 "2020-08-19T20:31:39Z")

</div>

Do the `exclusion.txt` file items contain the surrounding quotes? If so, they probably don’t need to be there.

---

<div class="post-metadata">

**Author:** ![clementb](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@clementb](https://forums.powershell.org/u/clementb)\
**Post date:** [August 19, 2020, 9:11pm UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/3 "2020-08-19T21:11:17Z")

</div>

Hello,

I tried with one, double quotes and without, but doesn’t work 😕

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [August 21, 2020, 11:37am UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/4 "2020-08-21T11:37:26Z")

</div>

We are left to assume what you have in `$target` and `$itemstosave` - the question I am stuck at is why are you including items in $itemstosave that you want to exclude. Just exclude them when making your list. If this isn’t the case, please provide details about what you’re actually running. If I run your test with a path as the $itemstosave, the exclusions were ignored in the format specified.

---

<div class="post-metadata">

**Author:** ![clementb](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@clementb](https://forums.powershell.org/u/clementb)\
**Post date:** [August 26, 2020, 4:18am UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/5 "2020-08-26T04:18:55Z")

</div>

Hello,

because in $itemtosave, i just set 4-5 generals folders. One folder can have 1000 or more files…

In $exclusion, I just want to exclude 2-3 extensions like \*.lck, \*.log or others…

> "If I run your test with a path as the $itemstosave, the exclusions were ignored in the format specified"

--\> Really ? :o I am running 7Zip 19.00, PWSH 5.1 (and 7.0.3).

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![clementb](https://avatars.discourse-cdn.com/v4/letter/c/3bc359/32.png) [@clementb](https://forums.powershell.org/u/clementb)\
**Post date:** [September 8, 2020, 10:15am UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/6 "2020-09-08T10:15:42Z")

</div>

Here a solution for someone who’s want do the same :  
_7zip a -t7z -m0=lzma2 -mx=9 -mmt=on -mhe=on -p"$resultPasswordArchive" $Target $itemsToSave1 -xr@“exclusion.txt”_  
In fileexclusion.txt, insert exclusions you want like :

> \*.log \*.lck

Problem solved. Clement.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/get-exclusions-from-file-powershell/14826/7 "2024-05-16T20:28:56Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


