PowerShell에서 색상 변경하는 방법

  1. PowerShell에서 색상 변경 소개
  2. PowerShell에서 [System.Enum] 클래스 사용
  3. PowerShell에서 콘솔 색상 변경
PowerShell에서 색상 변경하는 방법

이 글에서는 PowerShell을 사용하여 글꼴 색상, 스크립트의 배경 색상 및 콘솔 창 색상을 변경하는 방법에 대해 논의할 것입니다.

PowerShell에서 색상 변경 소개

이 명령은 PowerShell 콘솔, 콘솔 호스트에 대한 정보가 담긴 개체를 검색합니다.

명령:

$host

출력:

Name             : Windows PowerShell ISE Host
Version          : 5.1.22000.282
InstanceId       : 8cff2bea-868b-4d9e-b55a-06a3f4b8c20c
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-PH
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.Host.ISE.ISEOptions
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

PrivateData 속성에는 우리가 찾고 있는 모든 색상 속성이 있습니다.

명령:

$host.PrivateData

출력:

ErrorForegroundColor                      : #FFFF9494
ErrorBackgroundColor                      : #00FFFFFF
WarningForegroundColor                    : #FFFF8C00
WarningBackgroundColor                    : #00FFFFFF
VerboseForegroundColor                    : #FF00FFFF
VerboseBackgroundColor                    : #00FFFFFF
DebugForegroundColor                      : #FF00FFFF
DebugBackgroundColor                      : #00FFFFFF
ConsolePaneBackgroundColor                : #FF012456
ConsolePaneTextBackgroundColor            : #FF012456
ConsolePaneForegroundColor                : #FFF5F5F5
ScriptPaneBackgroundColor                 : #FFFFFFFF
ScriptPaneForegroundColor                 : #FF000000

색상은 $host.PrivateData 개체 내의 경고, 오류, 디버그, 자세한 정보 및 진행 스트림을 위해 설정됩니다. 이 값 중 하나를 변경하고 콘솔도 색상이 변경되는지 확인해 보세요.

명령:

$host.PrivateData.ErrorBackgroundColor = "White"

출력:

Black
DarkBlue
DarkGreen
DarkCyan
DarkRed
DarkMagenta
DarkYellow
Gray
DarkGray
Blue
Green
Cyan
Red
Magenta
Yellow
White

콘솔에 표시되는 출력은 기본 색상이 변경되지 않은 경우 일반 흰색 텍스트입니다. 다음 명령을 실행하여 콘솔 색상을 각 색상으로 표시하십시오.

명령:

[System.Enum]::GetValues('ConsoleColor') |
    ForEach-Object { Write-Host $_ -ForegroundColor $_ }

출력:

Write-Host로 글꼴 색상을 사용하여 색상 값을 표시합니다.

색상 조합이 어떤지 알고 싶다면 다음 명령을 사용할 수 있습니다. 이 명령은 모든 가능한 배경색에서 모든 가능한 전경색을 출력합니다.

명령:

$colors = [enum]::GetValues([System.ConsoleColor])
Foreach ($bgcolor in $colors) {
    Foreach ($fgcolor in $colors) {
        Write-Host "$fgcolor|"  -ForegroundColor $fgcolor -BackgroundColor $bgcolor -NoNewline
    }
    Write-Host " on $bgcolor"
}

출력:

전경 및 배경 콘솔 색상의 모든 가능한 조합 표시

PowerShell에서 콘솔 색상 변경

주요 콘솔 전경색과 배경 색상을 변경하는 것은 이전 개체와 약간 다릅니다. 아래 스니펫을 사용하여 텍스트 색상과 PowerShell의 콘솔 창 색상을 변경해 볼 수 있습니다.

명령:

$host.UI.RawUI.ForegroundColor = "DarkGreen"
$host.UI.RawUI.BackgroundColor = "Black"
cls

출력:

PowerShell에서 콘솔 색상 변경하기

튜토리얼이 마음에 드시나요? DelftStack을 구독하세요 YouTube에서 저희가 더 많은 고품질 비디오 가이드를 제작할 수 있도록 지원해주세요. 구독하다
Marion Paul Kenneth Mendoza avatar Marion Paul Kenneth Mendoza avatar

Marion specializes in anything Microsoft-related and always tries to work and apply code in an IT infrastructure.

LinkedIn

관련 문장 - PowerShell Color