The Setup
I have a folder structure that looks like:
C:\RootFolder
\file1.txt
\file2.txt
\license.txt
\Settings
\fileA.txt
\fileB.txt
\settings.txt
\OtherFolders
The Goal
Delete all of the files except for license.txt and settings.txt.
I would like in the end for only the following to remain:
C:\RootFolder
\license.txt
\Settings
\settings.txt
The Script to Far
$exclude = @('license.txt', 'settings.txt')
Get-ChildItem C:\RootFolder -recurse -exclude $exclude | foreach ($_) {remove-item $_.fullname -recurse:$false}
The Problem
Even though I specify -recurse:$false specifically, it always generates a message for each folder indicating that "recurse isn't specified" and saying it will delete all child items.
After this, the license.txt file remains, but the settings.txt file (in a subdirectory) does not.