Get-ChildItemColor provides colorization of outputs of Get-ChildItem
Cmdlet of PowerShell. It is based on Tim Johnson’s script, another script
by the PowerShell Guy, and PSColor.
It provides two main functionalities:
Get-ChildItemColor, which adds coloring to the output ofGet-ChildItem.Get-ChildItemColorFormatWide, which is colored version ofGet-ChildItemColor | Format-Wide. This usesWrite-Hostto output coloring, becauseGet-ChildItemColor | Format-Widedoes not allow multiple colors in one line.
Get-ChildItemColor has the following features:
- Both functions support pipelines — they are pipeline-aware, so they just return
untouhed output of
Get-ChildItemwhen used as a part of a pipeline. - As of v3.0.0, it no longer overloads
Out-Default, and thus does not have unintended consequences. - Both functions work as intended inside OneDrive directories.
- The wiki has additional instructions and examples.
Install from PowerShellGallery
PowerShellGet is required, which is included in Windows 10 and WMF5. If you are using PowerShell V3 or V4, you will need to install PowerShellGet.
Then, you can run Install-Module Get-ChildItemColor.
After cloning the repo or downloading the files, you can put files in /src folder into
Get-ChildItemColor folder under your PSModulePath
(e.g., $ENV:UserProfile\Documents\PowerShell\Modules for PowerShell 6 and
later). The master branch always contains the latest release version.
Install from Chocolatey
The module is available as a Chocolatey package. Install it using choco install get-childitemcolor.
When you import the module:
Import-Module Get-ChildItemColorit provides two functions, Get-ChildItemColorFormatWide and
Get-ChildItemColor.
You can add aliases to these functions for convenience. For example, I have the following in my profile[fn:pathProfile] (please do not put this into ISE profile[fn:pathProfileISE] as it does not work in ISE):
If (-Not (Test-Path Variable:PSise)) { # Only run this in the console and not in the ISE
Import-Module Get-ChildItemColor
Set-Alias l Get-ChildItemColor -option AllScope
Set-Alias ls Get-ChildItemColorFormatWide -option AllScope
}So l yields colored output of Get-ChildItem and ls yields colored output
of Get-ChildItem | Format-Wide equivalent.
Both functions have the following optional switches:
- -File
- Show only files.
- -Directory
- Show only directories.
Get-ChildItemColor has the following optional switch:
- -HumanReadableSize
- Unix style size string (e.g. M instead of MB, K instead of KB etc) (thanks to kforeverisback)
Get-ChildItemColorFormatWide has the following optional switches:
- -HideHeader
- Supress printing of headers (path on top).
- -TrailingSlashDirectory
- Add a trailing slash to directory names.
Note that if you want to use these switches as default, you have to define a function. For example,
function Get-ChildItemColorForceWideHHTS {
Get-ChildItemColorFormatWide -HideHeader -TrailingSlashDirectory -Force $Args[0]
}
Set-Alias ls Get-ChildItemColorForceWideHHTS -option AllScope[fn:pathProfile] $Home\[My ]Documents\PowerShell\Profile.ps1 or $Home\[My ]Documents\WindowsPowerShell\Profile.ps1
[fn:pathProfileISE] $Home\[My ]Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1
One can dynamically change the color scheme for different items, thanks to asidlo’s contribution. See the example below.
# Change color for directories to Blue
$GetChildItemColorTable.File['Directory'] = "Blue"
# Change color for executables to Green
ForEach ($Exe in $GetChildItemColorExtensions['ExecutableList']) {
$GetChildItemColorTable.File[$Exe] = "Green"
}One can create a new category and assign colors easily like the example below.
$GetChildItemColorExtensions['OfficeList'] = @(
".docx",
".pdf",
".pptx",
".xlsx"
)
ForEach ($Extension in $GetChildItemColorExtensions['OfficeList']) {
$GetChildItemColorTable.File.Add($Extension, "Green")
}You can adjust the vertical spacing using $Global:GetChildItemColorVerticalSpace. Default is 1 (PowerShell’s
default is 2).
$Global:GetChildItemColorVerticalSpace = 1- This section only contains old logs. See Releases for newer changelog.
- Add
HideHeaderswitch toGet-ChildItemColorFormatWide(#29)
- Better handling of header printout (#41)
- Add instructions about adding a new category.
- Fix uint32 error in cell width calculation. (Thanks to DanielCarmingham)
- Add Chocolatey install instructions. (Thanks to pauby)
- Fix #27, Display issue with Chinese. (Thanks to shiena)
- BUGFIX: Print directory names correctly when
-Recurseoption is used
- Re-organize folder structure
- Incorporate PSColor’s implementation of coloring the output of
Get-ChildItem. - Add
$Global:GetChildItemColorVerticalSpaceoption.
- PR #21: Added ReparsePoint (symlink) detection, matched color scheme with Linux (thanks to cmilanf)
- Make empty lines consistent between Get-ChildItemColor and Get-ChildItemColorFormatWide (Fixes #17)
- Add LICENSE
- Improve README (#15)
- Beautify code
- PR #13: Fallback to Gray when no
OriginalForegroundColor(thanks to mikesigs) - PR #12: Fix a typo (thanks to jqly)
- Robust to non-file entries (Issue #10)
- Revert back to previous implementation of
Get-ChildItemColorFormatWide
- The script changes
$Host.UI.RawUI.ForegroundColoronly and keep the item object intact Get-ChildItemColorFormatWideis basicallyGet-ChildItemColor | Format-Wide
- Better performance by reducing if’s
- Proper printing of
DirectoryEntryforFormatWidecase
- Published on PowerShellGallery
- Refactoring; separate out two functions
- Make it a PowerShell module
- Returns vanila
Get-Childitemresults forDictionaryEntrycases.
- Make function names consistent to the PowerShell naming convention (#8)
- Use parameters more consistently,
-Pathworks with paths with spaces (#3), and-Forceworks (#9)

