I have a folder named "Folder-Test". In the "Folder-Test" folder there are 3 sub-folders: "A", "B-1", "C-1".
How do I use "Get-ChildItem" to get a list of folders containing "-" in the name ("B-1", "C-1"). Then, use "ForEach-Object" and "Copy-Item" to copy the folders containing "-" in the name ("B-1", "C-1") to another folder.
My old code:
$path = (gci "D:\Folder-All" -Filter "Folder-Test" -Recurse).FullName
mkdir "D:\Another-Folder"
Get-ChildItem $path -Directory |
ForEach-Object {if (($_.enumeratefiles() | measure).count -gt 0)
{Copy-Item $path "D:\Another-Folder" -Filter {PSIsContainer} -Recurse -Force}
}