Is it possible to have breakpoint inside pipeline?

Hello,

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?

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 $_
}

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.

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.