Copy selected items in a directory with PS

~OSD~ 2,176 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
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,290 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,504 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,447 questions
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 21,590 Reputation points MVP
    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.