EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Format Table
Secondary Sidebar
PowerShell Tutorial
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell Format Table

By Priya PedamkarPriya Pedamkar

PowerShell Format Table

Introduction to PowerShell Format Table

We have many commands to see different types of outputs, but what if we need the output in a certain format that is more readable and understandable? So for that, we can use Powershell Format-Table, This commands display output in the format that we need. Let’s take one example, suppose we are going to display specific columns names like name, date, and CPU, etc, then we will use the command Format-Table. A normal command like Get-process will display all the columns which you may not require, but Get-process along with command Format-Table command will give only specific columns that we are needed. So with the help of Format-Table command, we can arrange and show only those columns which are necessary to see. This command is very useful where we wanted to show only limited details for better clarity of outputs. In Examples, we will see various types of uses and situations where we can use Format-Tablecommands to customize output format.

How to Format the Table in PowerShell?

See the below syntax we use for formatting our outputs.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,060 ratings)

Syntax:

Format-Table
[-AutoSize(auto adjust output)] [-RepeatHeader(After each new screen show header for clarity)] [-HideTableHeaders(Delete the column overlapping from output structure)] [-Wrap(Show the details in the next line if it exceed column width)] [[-Property] <Show the object properties>] [-GroupBy <here we can group output in another table based on the properties .>] [-View <allow us for custom table>] [-ShowError(just to send error in Pipeline)] [-DisplayError(show error on command line)] [<CommonParameters>]

When we will be writing very big scripts at that time we would like to see minimum columns for better understanding, rather than displaying everything. In the below example we are first executing a command Get-Process, to see the whole process and it’s all other properties and output we got PM(K), PM(M), WS(M), CPU(s), ID, SI, Processname as the columns. Here we can see Get-Process is displaying every attribute of process, you may not be able to understand every property.

Get-Process

Output:

PowerShell Format Table 1-1

But this output is a little confusing as it showing all columns. Let’s assume we are only interested in the ProcessName field than what? Here we will use Format-Table command to get specific columns that we are looking for. Let’s write an example for it. see the below example.

Get-Process | Format-Table ProcessName, Handles -auto

Output:

PowerShell Format Table 1-2

In the above example, we are only displaying ProcessName.You can write your own command to get only process Id or CPU details.

Examples of PowerShell Format Table

Below are the examples of PowerShell Format Table:

Example #1

We have discussed various ways to use Format-Table command, now let’s explore little more utility about it. Suppose we want to get a formatted table with sorted by their start date. You can see screen output for reference. Here we are getting all the processes available inside our system along with sorted by their start time.

Get-Process | Sort-Object StartTime | Format-Table -View StartTime

Output:

Get-Process

Example #2 

If We want to see today’s date along with the display error. Many times to get a better understanding of errors we can use this command.

Get-Date | Format-Table DayOfWeek,{ $_ / $null } -DisplayError

Output:

-DisplayError

The output is showing Thursday along with column #ERR. You can also try it. You will get different output depending on the date on which you are running this command. These practices are good to use if it is expected to give some wrong outputs.

Example #3

Many times we want to see our output in the group by, for example, suppose you want to see the all group by an inactive process to kill them Or all the process started on the same group by date, Or you may need to see all the process on the basis of the group by basepriority. Let’s see the below example. In this example, we are formatting our output group by basepriority.

get-process | format-table -groupby basepriority

Output:

basepriority

Let’s take another example of the group by, where we are displaying all the output groups by their status. Please see the below example along with the screen. You can try more group by according to the properties of services. Always raise a question that why you need this command. Assume your application is running very slow because of many inactive processes. So you can write a command group buy status and kill all the inactive processes to improve your system performance.

get-process | format-table -groupby status

Output:

PowerShell Format Table 1-6

Group by can also be used for file and folder system, for example, suppose you want to see all the file in formatted way of it’s last used, group by last modified. Here we are passing LastAccessTime as an argument to Group by. Let me tell you one example suppose you have a folder where 1000 files are there and these files are created on a daily basis, now if you want to see newly created or modified files group by particular dates, then it will be very easy to do with Groupby command. Please refer to the below example with the screen.

Get-ChildItem ./ranjan | Format-List -GroupBy LastAccessTime

Output:

LastAccessTime

Example #4

Let’s write a command which will show all the properties of a folder in the new line. See the below example, here we are formatting output for ranjan folder and all the output we are getting in the newline. Here we can also define or restrict the number of columns to be displayed in the newline.

Get-Item -Path ./ranjan | Format-List

Output:

PowerShell Format Table 1-8

Example #5

You can use alias also in PowerShell, For example in PowerShell to write format-table in short form, we can write FT. Let me tell you one example where we are going to use alias FT. In the below example we are using FT to get all processes with only three columns, processName, Handle and PagedMemorySize. It will be useful if you are writing a big script, where you can use a smaller name to make your script smaller.

Get-Process | FT ProcessName, Handles, PagedMemorySize -auto

Output:

PagedMemorySize

Example #6

We can also show the output in more than one column. Here we have a command called format-wide (fw). This command will be useful if you are going to display output with a very long list but this long list contains only one field.

Get-Process | Get-Member -Membertype method | Format-Wide name -column 3

Output:

PowerShell Format Table 1-10

Conclusion

Format-Table is very useful where we have a very large and complex output format, in such type of situation we can define our own format to minified or modified format of output for better understanding.

Recommended Articles

This is a guide to PowerShell Format Table. Here we discuss the introduction and how to format the table in PowerShell along with the examples. You may also look at the following articles to learn more –

  1. Examples to Implement Remove-Item in PowerShell
  2. Working of PowerShell String Functions
  3. Guide to Different PowerShell Tools
  4. Learn the Parameters of PowerShell Get-Location
  5. Examples to Implement PowerShell Get-Date
  6. Top 8 Examples of PowerShell Break
  7. PowerShell Get-Item | Examples
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
Data Visualization Training (15 Courses, 5+ Projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more