none
Copy-Item with file exclusions using -Exclude parameter RRS feed

  • Question

  • I am writing a PowerShell task using psake to copy over a directory structure and I am having some problems with the copy task:

    $ExclusionFiles = @("packages.config", "connectionStrings.config")
    
        Copy-Item -Path $SourcePath -Destination $DestinationPath -Exclude $ExclusionFiles -Recurse -Force

    When I run this command, it works properly but does not exclude the files that I specified in the $ExclusionFiles array parameter.

    How can I get the Copy-Item to properly exclude my specified files (they exist at the root of my source path directory)?

    Please advise.

    Thanks.  


    Thursday, April 7, 2016 6:27 PM

Answers

  • The source path must specify a wildcard ,for this to work:

    $source='c:\test\*'


    \_(ツ)_/

    • Marked as answer by vs2015junkie Friday, April 8, 2016 3:02 PM
    Thursday, April 7, 2016 6:53 PM
    Moderator

All replies