
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Use Custom Headers in PowerShell Output Table
If you want the specific properties in PowerShell, you need to use the Select-Object (Alias − Select) as a pipeline.
In the below example, we will retrieve the specific properties of the Spooler service.
Example
Get-Service Spooler | Select Name, DisplayName, Starttype, Status
Output
Name DisplayName StartType Status ---- ----------- --------- ------ Spooler Print Spooler Automatic Running
Now we will customize the header by renaming the “Name” property to the “Alias Name” by the Name and the Expression syntax inside the Select-object.
Example
Get- Service Spooler | Select @{N='Alias Name';E={$_.Name}}, DisplayName, Starttype, Status
You can also use other commands as well inside the expression.
Get-ComputerInfo | Select Csname, WindowsProductName, Csworkgroup
Output
CsName WindowsProductName CsWorkgroup ------ ------------------ ----------- DESKTOP-9435KM9 Windows 10 Pro WORKGROUP
In the above example, we need to add property “Computer Uptime” and for that, we need to add new command to the existing command using Expression syntax.
Example
Get- ComputerInfo | Select Csname, WindowsProductName, Csworkgroup, @{N='Days Uptime';E={((Get-Date) - (gcim Win32_OperatingSystem).LastBootUpTime).Days}}
Output
CsName WindowsProductName CsWorkgroup Days Uptime ------ ------------------ ----------- ----------- DESKTOP-9435KM9 Windows 10 Pro WORKGROUP 1
Advertisements