Copy selected items in a directory with PS

~OSD~ 2,201 Reputation points
2024-02-28T10:36:52.6133333+00:00

Hi, I have a directory, let's say C:\ProgramData\SourceDirectory SourceDirectory contains several sub-folders and .exe files. Copy-Item -Force -Recurse "C:\ProgramData\SourceDirectory" -Destination D:\TargetDir I want to include only the sub-folders in the SourceDirectory and exclude any .exe files in this SourceDirectory.

Windows for business Windows Server User experience PowerShell
Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 49,640 Reputation points MVP Volunteer Moderator
    2024-02-28T12:32:40.22+00:00

    You can use the -Exclude switch Copy-Item -Recurse -Force -Path "C:\ProgramData\SourceDirectory*" -Destination "D:\TargetDir" -Exclude "*.exe"


    hth Marcin

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.