我有结果Get-ChildItem,我想迭代这些,并显示他们的名字.默认情况下,如果我只是使用Write-Host然后我将它列在行中,如下所示:
PerfLogs Program Files Program Files (x86) Python31 Temp Users Windows
Run Code Online (Sandbox Code Playgroud)
但是,说我知道我希望它分成x列,我希望输出像这样:
PerfLogs Python31 Windows
Program Files Temp
Program Files (x86) Users
Run Code Online (Sandbox Code Playgroud)
如您所见,它首先将列列在列中,然后再列在列中.
知道如何获得这样的输出吗?理想情况下,它会使用最多的列,这些列可以放在屏幕上,并且每个列中的Name都对齐.
更新:感谢Roman,我现在可以使用目录颜色获得我的linux风格'ls'输出.建立他更新的脚本我有:
function color-ls
{
dir $args | Format-High -Print {
$item = $args
$fore = $host.UI.RawUI.ForegroundColor
$host.UI.RawUI.ForegroundColor = .{
if ($item[1].psIsContainer) {'Blue'}
elseif ($item[1].Extension -match '\.(exe|bat|cmd|ps1|psm1|vbs|rb|reg|dll|o|lib)') {'Red'}
elseif ($item[1].Extension -match '\.(zip|tar|gz|rar)') {'Yellow'}
elseif ($item[1].Extension -match '\.(py|pl|cs|rb|h|cpp)') {'Cyan'}
elseif ($item[1].Extension -match '\.(txt|cfg|conf|ini|csv|log|xml)') {'Green'}
else {$fore}
}
write-host $args[0] -NoNewLine
$host.UI.RawUI.ForegroundColor = $fore
} …Run Code Online (Sandbox Code Playgroud)