What is the correct syntax to exclude a folder's contents but not the folder itself

I have a powershell script that copies files from $source to $dest and it excludes some files types. It excludes my csv files and web.config files fine, but it won't exclude the Log folder contents. This is my script, what is the correct syntax to exclude the files contents but not the Log folder itself?

$exclude = @('Thumbs.db','*-Log.csv','web.config','Logs/*')

Get-ChildItem $source -Recurse -Exclude $exclude | Copy-Item -Destination {Join-Path $dest $_.FullName.Substring($source.length)}

Solution 1:

You'll need to setup a second Array with the paths you want to avoid and then add a filter in the pipe. Here's some sample code:

$exclude = @('Thumbs.db','*-Log.csv','web.config','Logs/*')
$directory = @("C:\logs")
Get-ChildItem $source -Recurse -Exclude $exclude | where {$directory -notcontains $_.DirectoryName}