Get-ChildItem works in console but not in PowerGUI Editor debugger

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of David Stiff David Stiff 1 year, 10 months ago.

  • Author
    Posts
  • #21831
    Profile photo of David Stiff
    David Stiff
    Participant

    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

  • #21837
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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?

  • #21861
    Profile photo of David Stiff
    David Stiff
    Participant

    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

  • #21867
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    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'
    
  • #21896
    Profile photo of David Stiff
    David Stiff
    Participant

    That was it. Thanks!

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

    -dave

You must be logged in to reply to this topic.