Clean up old branches Modify array with branches you want to keep git branch | %{ $_.Trim() } | ?{ @('main','master') -notcontains $_} | %{ git branch -D $_ }