Is it possible to have breakpoint inside pipeline?

This topic contains 3 replies, has 3 voices, and was last updated by  GS 3 years ago.

  • Author
  • #27597



    Trying to figure out how to set breakpoint when debugging pipeline. Example is below

    get-childitem c:\ |where {$_.LastWriteTime -le (Get-Date).AddDays(-180)} | Remove-Item

    I want to have a breakpoint on "Remove-Item" invocation at the end of the statement. Is it possible to do?

  • #27598

    Dave Wyatt

    That's a big awkward. You technically can set a breakpoint on that command, but it triggers at the beginning of the pipeline, rather than for each object. It's simpler to stick the call to Remove-Item in a ForEach-Object block, at which point the breakpoint is simple (either by using Set-PSBreakpoint -Command Remove-Item , or by putting Remove-Item on its own line and using Set-PSBreakpoint -Line or the F9 key in the ISE.)

    get-childitem c:\ |
    where {$_.LastWriteTime -le (Get-Date).AddDays(-180)} |
    ForEach-Object {
        Remove-Item $_
  • #27604

    Rob Simmers

    If you are debugging if Remove-Item is removing what you expect, you should just use the WhatIf switch for the Remove-Item command:

    get-childitem c:\ |where {$_.LastWriteTime -le (Get-Date).AddDays(-180)} | Remove-Item -WhatIf

    The WhatIf switch is typically available on any command that is making a change, so your Set, Remove, etc. will have the switch, but Get commands are just pulling information for example so they do not.

  • #27609


    No, I really needed to catch some errors being thrown in Remove-Item statement due to path beeing too long. Dave's suggestion worked for me.

You must be logged in to reply to this topic.