Skip to content

Instantly share code, notes, and snippets.

@josheinstein
Created November 30, 2016 20:15
Show Gist options
  • Save josheinstein/8cededa256ae0f39a2df573f92087f9c to your computer and use it in GitHub Desktop.
Save josheinstein/8cededa256ae0f39a2df573f92087f9c to your computer and use it in GitHub Desktop.
#.SYNOPSIS
# Removes all .DS_Store files from the current directory as well
# as any subdirectories.
#.DESCRIPTION
# .DS_Store is an artifact left by Mac OSX. On Mac that is harmless
# to remove, but otherwise pretty annoying. They tend to make their
# way into remote file shares and zip files and are not hidden by
# default in Windows.
function Remove-DSStore {
[CmdletBinding(DefaultParameterSetName='LiteralPath', SupportsShouldProcess=$true)]
param(
# The path to one or more directories to remove .DS_Store files from.
[Parameter(ParameterSetName='Path', Position=1)]
[String[]]$Path = '.',
# The path to one or more directories to remove .DS_Store files from.
[Alias('PSPath')]
[Parameter(ParameterSetName='LiteralPath', ValueFromPipelineByPropertyName=$true)]
[String[]]$LiteralPath = '.',
# If NoRecurse is specified, subdirectories will not be checked for .DS_Store.
[Parameter()]
[Switch]$NoRecurse
)
process {
$GetChildItemArgs = @{
Filter = '.DS_Store'
Recurse = $true
Force = $true
}
if ($PSCmdlet.ParameterSetName -eq 'Path') {
$GetChildItemArgs['Path'] = $Path
}
elseif ($PSCmdlet.ParameterSetName -eq 'LiteralPath') {
$GetChildItemArgs['LiteralPath'] = $LiteralPath
}
if ($NoRecurse) {
[Void]$GetChildItemArgs.Remove('Recurse')
}
Get-ChildItem @GetChildItemArgs | Remove-Item -WhatIf:([Bool]$WhatIfPreference.IsPresent)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment