Nuke .DS_Store Files from Multiple Repositories with PowerShell


I hate when .DS_Store files get checked in and create conflicts when working on different Mac computers.

In the StackOverflow referenced below I found the answer. In order to do it in all my repositories I wrote this little PowerShell script:

Get-ChildItem -Directory | ForEach-Object { 
    Write-Host "Change directory to repo"
    Set-Location $_.FullName
    Get-Location | Write-Host

    find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
    echo .DS_Store >> .gitignore

    git add .gitignore
    git commit -m '.DS_Store banished!'
    git push