Author Posts

January 13, 2015 at 1:42 pm

Hello,

I am trying to create a one-liner to recursively copy and flatten a folder structure. This works in the PowerShell console but in the PowerGUI Editor debugger, no files are copied.

Get-ChildItem c:\SourceFolder\* -Include *.dll,*.pdb,*.tlb,*.exe -Recurse | Copy-Item -Destination C:\TargetFolder -Force

Am I doing something wrong? Or do debuggers act differently that the console?

Thanks,
Dave

January 13, 2015 at 8:20 pm

Well.. there are some things that behave differently in a debugger; mainly certain automatic variables such as $PSCmdlet, $MyInvocation, and so on. You're not using any of those, and I'm not sure why this wouldn't be working. Have you tried running just the Get-ChildItem part to make sure the proper results are coming out of there? Do you get any error messages?

January 14, 2015 at 9:55 am

Hi Dave,

it appears to be related to using variables for Get-ChildItem. My code is:

$source = 'C:\Builds\bin'
$extensions = '*.dll,*.pdb,*.tlb,*.exe'
Get-ChildItem $source\* -Include $extensions -Recurse

Using this, even in the console, produces no output. Is either $source or $extensions being interpreted incorrectly (or not as I expect)?

Thanks,
Dave

January 14, 2015 at 6:25 pm

Your $extensions variable should be an array of strings; what you currently have is a single string with a bunch of comma-separated values. Try this:

$extensions = '*.dll', '*.pdb', '*.tlb', '*.exe'

January 15, 2015 at 12:46 pm

That was it. Thanks!

I'll pay closer attention to the cmdlet help parameter types from now on.

-dave