Is it possible to have breakpoint inside pipeline?

Welcome Forums General PowerShell Q&A Is it possible to have breakpoint inside pipeline?

This topic contains 3 replies, has 3 voices, and was last updated by

3 years, 7 months ago.

  • Author
  • #27597

    Points: 12
    Rank: Member


    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

    Points: 0
    Rank: Member

    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

    Points: 513
    Helping Hand
    Rank: Major Contributor

    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

    Points: 12
    Rank: Member

    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.

The topic ‘Is it possible to have breakpoint inside pipeline?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort