document type: cmdlet external help file: ColorScripts-Enhanced-help.xml HelpUri: https://github.com/Nick2bad4u/PS-Color-Scripts-Enhanced/blob/main/ColorScripts-Enhanced/en-US/Clear-ColorScriptCache.md Module Name: ColorScripts-Enhanced ms.date: 11/14/2025 PlatyPS schema version: 2024-05-01
Remove cached colorscript output files.
Clear-ColorScriptCache [-All] [-Path <String>] [-DryRun] [-PassThru] [-Quiet] [-NoAnsiOutput] [-WhatIf] [-Confirm] [<CommonParameters>]
Clear-ColorScriptCache [-Name <String[]>] [-Category <String[]>] [-Tag <String[]>] [-Path <String>] [-DryRun] [-PassThru] [-Quiet] [-NoAnsiOutput] [-WhatIf] [-Confirm] [<CommonParameters>]
Clear-ColorScriptCache [[-Name] <string[]>] [[-Path] <string>] [[-Category] <string[]>] [[-Tag] <string[]>] [-All] [-DryRun] [-PassThru] [-Quiet] [-NoAnsiOutput] [-WhatIf] [-Confirm] [<CommonParameters>]
The Clear-ColorScriptCache cmdlet removes cached output files generated by the ColorScripts-Enhanced module. Cache files store pre-rendered script output to improve performance during subsequent invocations.
You can delete cache files selectively using the -Name parameter with wildcard patterns, or remove all cache files at once with the -All parameter. The cmdlet also supports filtering by -Category and -Tag to target specific subsets of cached scripts.
Unmatched script names report a Missing status in the results. Use -DryRun to preview removal actions without modifying the filesystem, and -Path to target an alternate cache directory (useful for custom cache configurations or CI/CD environments).
Cache files are automatically regenerated the next time Show-ColorScript executes the corresponding script.
For automation scenarios, combine -PassThru to capture structured results, -Quiet to suppress the summary message, or -NoAnsiOutput to emit plain-text summaries without ANSI color codes.
Clear-ColorScriptCache -All -Confirm:$falseRemoves every cache file in the default cache directory without prompting for confirmation. This is useful for completely refreshing the cache after module updates or when troubleshooting display issues.
Clear-ColorScriptCache -Name 'aurora-*' -DryRunPreviews which aurora-themed cache files would be removed without actually deleting them. The output shows the cache files that match the pattern, allowing you to verify the selection before committing to the deletion.
Clear-ColorScriptCache -Name bars -Path $env:TEMP -Confirm:$falseClears the cache file for the 'bars' script from a custom cache directory located in the TEMP folder. This is useful when working with the COLOR_SCRIPTS_ENHANCED_CACHE_PATH environment variable or testing alternative cache locations.
Clear-ColorScriptCache -Category Animation -WhatIfShows what would happen if all cache files for scripts in the Animation category were removed. The -WhatIf parameter prevents actual deletion and displays the intended actions.
Get-ColorScriptList -Tag retro | Clear-ColorScriptCache -DryRunUses pipeline input to preview the removal of cache files for all scripts tagged as 'retro'. Combines filtering by tag with a dry-run preview before committing to the deletion.
Clear-ColorScriptCache -Name 'test-*', 'demo-*' -Confirm:$falseRemoves cache files for all scripts whose names begin with 'test-' or 'demo-' without confirmation. Multiple wildcard patterns can be specified as an array.
# Clean cache and rebuild for optimization
Clear-ColorScriptCache -All -Confirm:$false
New-ColorScriptCache -PassThru | Measure-Object
Write-Host "Cache rebuilt successfully"Performs a complete cache refresh by clearing all and rebuilding, then shows statistics.
# Clear old cache entries older than 30 days
$cacheDir = "$env:APPDATA\ColorScripts-Enhanced\cache"
$thirtyDaysAgo = (Get-Date).AddDays(-30)
Get-ChildItem $cacheDir -Filter "*.cache" |
Where-Object { $_.LastWriteTime -lt $thirtyDaysAgo } |
ForEach-Object {
Clear-ColorScriptCache -Name $_.BaseName -Confirm:$false
}
Write-Host "Old cache files cleaned"Removes cache files that haven't been updated in more than 30 days.
# Cache management report
$cacheDir = "$env:APPDATA\ColorScripts-Enhanced\cache"
$beforeCount = @(Get-ChildItem $cacheDir -Filter "*.cache" -ErrorAction SilentlyContinue).Count
Clear-ColorScriptCache -Category Geometric -Confirm:$false
$afterCount = @(Get-ChildItem $cacheDir -Filter "*.cache" -ErrorAction SilentlyContinue).Count
Write-Host "Cleared $($beforeCount - $afterCount) geometric cache files"Shows statistics about cache clearing operations.
# Troubleshooting - clear and rebuild specific script
$scriptName = "mandelbrot-zoom"
Clear-ColorScriptCache -Name $scriptName -Confirm:$false
New-ColorScriptCache -Name $scriptName -Force
Show-ColorScript -Name $scriptNameClears and rebuilds cache for a single script, then displays it for verification.
# Filter by multiple categories
Clear-ColorScriptCache -Category Geometric,Abstract -DryRun |
Select-Object CacheFile |
Measure-ObjectShows how many cache files would be deleted if filtering by multiple categories.
Remove every cache file in the target directory. This parameter is mutually exclusive with -Name, -Category, and -Tag. When specified, all filtering parameters are ignored and the entire cache is cleared.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Filter the target scripts by category before evaluating cache entries. Only cache files for scripts matching the specified categories will be considered for removal. Accepts an array of category names and can be combined with -Tag for more precise filtering.
Type: System.String[]
DefaultValue: ""
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 2
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Prompts you for confirmation before running the cmdlet. By default, this is enabled to prevent accidental deletion of cache files. Use -Confirm:$false to bypass the confirmation prompt.
Type: System.Management.Automation.SwitchParameter
DefaultValue: True
SupportsWildcards: false
Aliases:
- cf
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Preview removal actions without deleting any files. The cmdlet will display which cache files would be removed but will not modify the filesystem. This is useful for verifying your selection criteria before committing to the deletion.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Return detailed result objects for each cache entry processed. Without this switch, the cmdlet only writes a summary message. Each pass-through record includes the script name, cache file path, status, and any associated error text for further inspection or reporting.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Suppress the summary message emitted after cache removal completes. Use this switch when running in quiet automation contexts where only structured output (such as -PassThru records, warnings, or errors) should be produced.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Disable ANSI color sequences in the summary output. This is helpful for consoles or log processors that do not interpret ANSI styling, ensuring the summary text remains legible in plain text.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases:
- NoColor
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Names or wildcard patterns identifying cache files to remove. Accepts pipeline input and property binding from objects with a Name property. Wildcard characters (*, ?) are supported for pattern matching. Mutually exclusive with -All.
Type: System.String[]
DefaultValue: None
SupportsWildcards: true
Aliases: []
ParameterSets:
- Name: (All)
Position: 0
IsRequired: false
ValueFromPipeline: true
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Alternate cache directory to operate against. Defaults to the module's standard cache path if not specified. Use this parameter when working with custom cache locations set via the COLOR_SCRIPTS_ENHANCED_CACHE_PATH environment variable, or when managing cache files in alternative directories for testing or CI/CD purposes.
Type: System.String
DefaultValue: None
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 1
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Filter the target scripts by metadata tag before evaluating cache entries. Only cache files for scripts with matching tags will be considered for removal. Accepts an array of tag names and can be combined with -Category for more granular control over which cache files are targeted.
Type: System.String[]
DefaultValue: ""
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
Position: 3
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""Shows what would happen if the cmdlet runs without actually executing the operation. The cmdlet displays the actions it would perform but does not modify the filesystem. This is a standard PowerShell common parameter that works similarly to -DryRun but follows PowerShell's built-in conventions.
Type: System.Management.Automation.SwitchParameter
DefaultValue: False
SupportsWildcards: false
Aliases:
- wi
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ""This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
You can pipe script names to this cmdlet. Each name will be evaluated for cache file removal based on the specified parameters.
You can pipe an array of script names to this cmdlet. This is particularly useful when combining with Get-ColorScriptList to filter scripts by various criteria before clearing their caches.
You can pipe objects with a Name property to this cmdlet. The cmdlet will extract the Name property value and use it to identify cache files for removal.
Returns status records for each processed cache file. Each output object contains the following properties:
- Status: The result of the operation (
Removed,Missing,DryRun, orError) - CacheFile: The full path to the cache file that was processed
- Message: Descriptive text explaining the outcome of the operation
- ScriptName: The name of the script associated with the cache file
# Complete cache refresh
Clear-ColorScriptCache -All -Confirm:$false
New-ColorScriptCache -Force
Write-Host "Cache rebuilt successfully"# Clear only obsolete entries
Clear-ColorScriptCache -Name "deprecated-*", "test-*" -Confirm:$false
# Verify what would be removed first
Clear-ColorScriptCache -Name "draft-*" -DryRun# Clear cache files older than 60 days
$cacheDir = (Get-ColorScriptConfiguration).Cache.Path
$cutoffDate = (Get-Date).AddDays(-60)
Get-ChildItem $cacheDir -Filter "*.cache" |
Where-Object { $_.LastWriteTime -lt $cutoffDate } |
ForEach-Object {
Clear-ColorScriptCache -Name $_.BaseName -Confirm:$false
}# Remove caches for experimental category
Clear-ColorScriptCache -Category Experimental -Confirm:$false
# Clear outdated tag
Clear-ColorScriptCache -Tag deprecated -Confirm:$false
# Clear multiple categories at once
Clear-ColorScriptCache -Category @("Demo", "Test", "Draft") -Confirm:$false# Keep only recommended scripts, clear everything else
$keep = Get-ColorScriptList -Tag Recommended -AsObject | Select-Object -ExpandProperty Name
$all = Get-ColorScriptList -AsObject | Select-Object -ExpandProperty Name
$remove = $all | Where-Object { $_ -notin $keep }
$remove | ForEach-Object { Clear-ColorScriptCache -Name $_ -Confirm:$false }# Analyze cache before cleanup
$cacheDir = (Get-ColorScriptConfiguration).Cache.Path
$before = (Get-ChildItem $cacheDir -Filter "*.cache" | Measure-Object -Property Length -Sum).Sum
Clear-ColorScriptCache -Category Demo -DryRun
Write-Host "Current cache size: $([math]::Round($before / 1MB, 2)) MB"# Generate report of cleanup operations
$report = Clear-ColorScriptCache -Name "test-*", "debug-*" -Confirm:$false
$report | Group-Object Status | ForEach-Object {
Write-Host "$($_.Name): $($_.Count) items"
}# Calculate disk space freed
$before = (Get-ChildItem (Get-ColorScriptConfiguration).Cache.Path -Filter "*.cache" | Measure-Object -Property Length -Sum).Sum
Clear-ColorScriptCache -All -Confirm:$false
$after = (Get-ChildItem (Get-ColorScriptConfiguration).Cache.Path -Filter "*.cache" -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
Write-Host "Freed: $([math]::Round(($before - $after) / 1MB, 2)) MB"# Clean build: clear all cache before rebuilding
Clear-ColorScriptCache -All -Confirm:$false
New-ColorScriptCache -Tag Recommended -Force
Write-Host "Cache ready for deployment"# Keep production scripts, clear development
Clear-ColorScriptCache -Tag "development,experimental" -Confirm:$false
# Preserve cache for critical scripts
$critical = @("bars", "arch", "mandelbrot-zoom")
$scripts = Get-ColorScriptList -AsObject | Select-Object -ExpandProperty Name
$toRemove = $scripts | Where-Object { $_ -notin $critical }
$toRemove | ForEach-Object { Clear-ColorScriptCache -Name $_ -Confirm:$false }# Verify cache issues and fix
$problemScripts = Get-ColorScriptList -AsObject |
Where-Object {
-not (Test-Path "$env:APPDATA\ColorScripts-Enhanced\cache\$($_.Name).cache")
}
Write-Host "Scripts without cache: $($problemScripts.Count)"
$problemScripts | ForEach-Object {
Write-Host "Rebuilding: $($_.Name)"
New-ColorScriptCache -Name $_.Name -Force
}Author: Nick Module: ColorScripts-Enhanced
Cache files are stored with a .cache extension in the module's cache directory. Each cache file corresponds to a single colorscript and contains the pre-rendered ANSI output.
Cache files are automatically regenerated the next time Show-ColorScript executes the corresponding script. This regeneration happens transparently and does not require manual intervention.
The default cache path is exposed via the module's $CacheDir variable and can be overridden using the COLOR_SCRIPTS_ENHANCED_CACHE_PATH environment variable.
When using -DryRun or -WhatIf, the cmdlet will still validate that the cache directory exists and report any issues, but will not perform any deletions.
Filtering by -Category or -Tag requires that the scripts have associated metadata. Scripts without metadata will not match these filters.
- Always use
-DryRunor-WhatIfbefore destructive operations - Use
-Confirm:$falseonly when you're certain about the operation - Archive cache before major cleanup operations for recovery
- Monitor disk space regularly for cache growth
- Use selective cleaning instead of full clearing when possible
- Keep track of critical scripts that shouldn't be cleared
- Schedule automated cleanups during maintenance windows
- Test cleanup operations in non-production first
- "No cache files found": Use
-AsObjectto verify which scripts have caches - "Permission denied": Verify write access to cache directory
- "Cache not regenerating": Scripts may have rendering issues; test with
-NoCache