C# ASP.NET SQL SERVER

Powershell Copy-Item does not honor the exclude parameter

I've been having a hard time getting Powershell's Copy-Item to work for me. My problem is that the -exclude parameter for the Copy-Item only honors the excluded items for the root directory in the destination but not for sub-directories if you also include the recurse parameter.

I believe that I have finally solved the problem with this snippet of powershell:

$source = 'd:\t1'

$dest = 'd:\t2'

$exclude = @('*.pdb','*.config')

$items = Get-ChildItem $source -Recurse -Exclude $exclude

foreach($item in $items)

{

      $target = Join-Path $dest $item.FullName.Substring($source.length)

      if( -not( $item.PSIsContainer -and (Test-Path($target))))

      {

            Copy-Item -Path $item.FullName -Destination $target

      }

}

» Similar Posts

  1. Powershell script to remove empty directories
  2. Powershell Ripped Media Renaming Script
  3. Windows Management Framework Core is already installed on your system

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=152

» Comments

    There are no comments. Kick things off by filling out the form below.

» Leave a Comment