Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Remove contents of nested folder excluding specific files files (powershell)

$
0
0

I need to remove the contents of a folder with powershell but keep a few files inside nested folders. I have tried witht he remove-item cmdlet but when i use the recurse switch, it ignores my excludes.. for example:

remove-item 'c:\inetpub\MySite\*'  -exclude 'c:\inetput\MySite\app_config\connectionstring.config','c:\inetput\MySite\app_config\Include\appsettings.config' -recurse -force

So what I want to do is:

Remove contents in c:\inetpub\MySite,
except for:
c:\inetput\MySite\app_config\connectionstring.config
and
c:\inetput\MySite\app_config\Include\appsettings.config


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>