다음을 통해 공유


형식 명령을 사용하여 출력 보기 변경

PowerShell에는 특정 개체에 대한 속성이 표시되는 방식을 제어할 수 있는 cmdlet 집합이 있습니다. 모든 cmdlet의 이름은 동사 Format로 시작합니다. 표시할 속성을 선택할 수 있습니다.

Get-Command -Verb Format -Module Microsoft.PowerShell.Utility
CommandType     Name               Version    Source
-----------     ----               -------    ------
Cmdlet          Format-Custom      6.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Format-Hex         6.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Format-List        6.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Format-Table       6.1.0.0    Microsoft.PowerShell.Utility
Cmdlet          Format-Wide        6.1.0.0    Microsoft.PowerShell.Utility

이 문서에서는 Format-Wide, Format-ListFormat-Table cmdlet에 대해 설명합니다.

PowerShell의 각 개체 형식에는 표시할 속성을 선택하지 않을 때 사용되는 기본 속성이 있습니다. 각 cmdlet은 동일한 속성 매개 변수를 사용하여 표시할 속성을 지정합니다. Format-Wide 단일 속성만 표시하므로 Property 매개 변수는 단일 값만 사용하지만 Property 매개 변수는 Format-ListFormat-Table 속성 이름 목록을 허용합니다.

이 예제에서 Get-Process cmdlet의 기본 출력은 Internet Explorer의 두 인스턴스가 실행 중임을 보여 줍니다.

Get-Process -Name iexplore

Process 개체의 기본 형식은 다음과 같은 속성을 표시합니다.

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
     32    25.52      10.25      13.11   12808   1 iexplore
     52    11.46      26.46       3.55   21748   1 iexplore

단일 항목 출력에 Format-Wide 사용

기본적으로 Format-Wide cmdlet은 개체의 기본 속성만 표시합니다. 각 개체와 연결된 정보는 단일 열에 표시됩니다.

Get-Command -Verb Format | Format-Wide
Format-Custom          Format-Hex
Format-List            Format-Table
Format-Wide

기본이 아닌 속성을 지정할 수도 있습니다.

Get-Command -Verb Format | Format-Wide -Property Noun
Custom                 Hex
List                   Table
Wide

열을 사용하여 Format-Wide 표시 제어

Format-Wide cmdlet을 사용하면 한 번에 하나의 속성만 표시할 수 있습니다. 이렇게 하면 여러 열에 큰 목록을 표시하는 데 유용합니다.

Get-Command -Verb Format | Format-Wide -Property Noun -Column 3
Custom                 Hex                  List
Table                  Wide

목록 보기에 Format-List 사용

Format-List cmdlet은 각 속성에 레이블이 지정되고 별도의 줄에 표시되는 목록 형식으로 개체를 표시합니다.

Get-Process -Name iexplore | Format-List
Id      : 12808
Handles : 578
CPU     : 13.140625
SI      : 1
Name    : iexplore

Id      : 21748
Handles : 641
CPU     : 3.59375
SI      : 1
Name    : iexplore

원하는 만큼 속성을 지정할 수 있습니다.

Get-Process -Name iexplore | Format-List -Property ProcessName,FileVersion,StartTime,Id
ProcessName : iexplore
FileVersion : 11.00.18362.1 (WinBuild.160101.0800)
StartTime   : 10/22/2019 11:23:58 AM
Id          : 12808

ProcessName : iexplore
FileVersion : 11.00.18362.1 (WinBuild.160101.0800)
StartTime   : 10/22/2019 11:23:57 AM
Id          : 21748

와일드카드와 함께 Format-List 사용하여 자세한 정보 가져오기

Format-List cmdlet을 사용하면 와일드카드를 Property 매개 변수의 값으로 사용할 수 있습니다. 이렇게 하면 자세한 정보를 표시할 수 있습니다. 개체에 필요한 것보다 많은 정보가 포함되는 경우가 많으므로 PowerShell에서 기본적으로 모든 속성 값을 표시하지는 않습니다. 개체의 모든 속성을 표시하려면 Format-List -Property * 명령을 사용합니다. 다음 명령은 단일 프로세스에 대해 60줄 이상의 출력을 생성합니다.

Get-Process -Name iexplore | Format-List -Property *

Format-List 명령은 세부 정보를 표시하는 데 유용하지만 많은 항목이 포함된 출력 개요를 원하는 경우 더 간단한 테이블 형식 보기가 더 유용한 경우가 많습니다.

테이블 형식 출력에 Format-Table 사용

속성 이름이 지정되지 않은 Format-Table cmdlet을 사용하여 Get-Process 명령의 출력 형식을 지정하는 경우 Format cmdlet 없이도 동일한 출력을 얻을 수 있습니다. 기본적으로 PowerShell은 Process 개체를 테이블 형식으로 표시합니다.

Get-Service -Name win* | Format-Table
Status   Name               DisplayName
------   ----               -----------
Running  WinDefend          Windows Defender Antivirus Service
Running  WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se...
Running  Winmgmt            Windows Management Instrumentation
Running  WinRM              Windows Remote Management (WS-Manag...

비고

Get-Service Windows 플랫폼에서만 사용할 수 있습니다.

Format-Table 출력 개선

테이블 형식 보기는 많은 정보를 표시하는 데 유용하지만 표시가 데이터에 비해 너무 좁은지 해석하기 어려울 수 있습니다. 이전 예제에서는 출력이 잘립니다. Format-Table 명령을 실행할 때 AutoSize 매개 변수를 지정하면 PowerShell은 표시된 실제 데이터에 따라 열 너비를 계산합니다. 이렇게 하면 열을 쉽게 읽을 수 있습니다.

Get-Service -Name win* | Format-Table -AutoSize
Status  Name                DisplayName
------  ----                -----------
Running WinDefend           Windows Defender Antivirus Service
Running WinHttpAutoProxySvc WinHTTP Web Proxy Auto-Discovery Service
Running Winmgmt             Windows Management Instrumentation
Running WinRM               Windows Remote Management (WS-Management)

Format-Table cmdlet은 여전히 데이터를 잘릴 수 있지만, 화면의 끝부분에서만 잘립니다. 마지막으로 표시된 속성이 아닌 속성은 가장 긴 데이터 요소가 올바르게 표시되는 데 필요한 크기만큼 지정됩니다.

Get-Service -Name win* |
    Format-Table -Property Name, Status, StartType, DisplayName, DependentServices -AutoSize
Name                 Status StartType DisplayName                               DependentServi
                                                                                ces
----                 ------ --------- -----------                               --------------
WinDefend           Running Automatic Windows Defender Antivirus Service        {}
WinHttpAutoProxySvc Running    Manual WinHTTP Web Proxy Auto-Discovery Service  {NcaSvc, iphl…
Winmgmt             Running Automatic Windows Management Instrumentation        {vmms, TPHKLO…
WinRM               Running Automatic Windows Remote Management (WS-Management) {}

Format-Table 명령은 속성이 중요도 순서로 나열된다고 가정합니다. cmdlet은 시작 부분에 가장 가까운 속성을 완전히 표시하려고 시도합니다. Format-Table 명령이 모든 속성을 표시할 수 없으면 일부 열이 디스플레이에서 제거됩니다. 이 동작은 DependentServices 속성 이전 예제에서 확인할 수 있습니다.

Format-Table 출력을 열로 래핑

Wrap 매개 변수를 사용하여 긴 Format-Table 데이터가 표시 열 내에서 래핑되도록 강제할 수 있습니다. Wrap 매개 변수를 사용하면 자동 크기 조정지정하지 않으면 기본 설정을 사용하기 때문에 예상한 것과 다를 수 있습니다.

Get-Service -Name win* |
    Format-Table -Property Name, Status, StartType, DisplayName, DependentServices -Wrap
Name                 Status StartType DisplayName                               DependentServi
                                                                                ces
----                 ------ --------- -----------                               --------------
WinDefend           Running Automatic Windows Defender Antivirus Service        {}
WinHttpAutoProxySvc Running    Manual WinHTTP Web Proxy Auto-Discovery Service  {NcaSvc,
                                                                                iphlpsvc}
Winmgmt             Running Automatic Windows Management Instrumentation        {vmms,
                                                                                TPHKLOAD,
                                                                                SUService,
                                                                                smstsmgr…}
WinRM               Running Automatic Windows Remote Management (WS-Management) {}

Wrap 매개 변수를 단독으로 사용하면 처리 속도가 크게 느려지지 않습니다. 그러나 AutoSize 사용하여 큰 디렉터리 구조의 재귀 파일 목록의 형식을 지정하는 데 시간이 오래 걸리고 첫 번째 출력 항목을 표시하기 전에 많은 메모리를 사용할 수 있습니다.

시스템 로드에 대해 신경 쓰지 않는 경우 AutoSizeWrap 매개 변수와 잘 작동합니다. 초기 열은 여전히 한 줄에 항목을 표시하는 데 필요한 만큼 너비를 사용하지만 필요한 경우 최종 열은 래핑됩니다.

비고

가장 넓은 열을 먼저 지정하면 일부 열이 표시되지 않을 수 있습니다. 최상의 결과를 위해 가장 작은 데이터 요소를 먼저 지정합니다.

다음 예제에서는 가장 넓은 속성을 먼저 지정합니다.

Get-Process -Name iexplore |
    Format-Table -Wrap -AutoSize -Property FileVersion, Path, Name, Id

포맷팅을 수행하더라도 최종 ID 열은 생략됩니다.

FileVersion                          Path                                                  Nam
                                                                                           e
-----------                          ----                                                  ---
11.00.18362.1 (WinBuild.160101.0800) C:\Program Files (x86)\Internet Explorer\IEXPLORE.EXE iex
                                                                                           plo
                                                                                           re
11.00.18362.1 (WinBuild.160101.0800) C:\Program Files\Internet Explorer\iexplore.exe       iex
                                                                                           plo
                                                                                           re

테이블 출력 구성

테이블 형식 출력 컨트롤에 대한 또 다른 유용한 매개 변수는 GroupBy . 특히 테이블 형식 목록이 길면 비교하기 어려울 수 있습니다. GroupBy 매개 변수는 속성 값에 따라 출력을 그룹화합니다. 예를 들어 더 쉽게 검사할 수 있도록 StartType 서비스를 그룹화하여 속성 목록에서 StartType 값을 생략할 수 있습니다.

Get-Service -Name win* | Sort-Object StartType | Format-Table -GroupBy StartType
   StartType: Automatic
Status   Name               DisplayName
------   ----               -----------
Running  WinDefend          Windows Defender Antivirus Service
Running  Winmgmt            Windows Management Instrumentation
Running  WinRM              Windows Remote Management (WS-Managem…

   StartType: Manual
Status   Name               DisplayName
------   ----               -----------
Running  WinHttpAutoProxyS… WinHTTP Web Proxy Auto-Discovery Serv…