Power shell универсальный


Often you may want to use the Format-Table cmdlet in PowerShell to create a table and specify the width of columns in the table.

Method 1: Use Format-Table with AutoSize Parameter

The -AutoSize parameter ensures that each column is as wide as it needs to be in the table to display the longest value in each column.

Method 2: Use Format-Table with Width Parameter

 | -Property @{ e=''; width=8 }, DisplayName

This particular example uses the width parameter to specify that the column named Name should only show the first 8 characters of each string, while the DisplayName column should simply show the default number of characters.

Example 1: How to Use Format-Table with AutoSize Parameter in PowerShell

Suppose that we use the Get-Service cmdlet to get a list of all services on our computer and then use the Format-Table cmdlet to display the services in a table:

Power shell универсальный

Notice that some of the strings in the Name column are cut off.

PowerShell Format-Table control width of each column with autosize

Notice that the Name column is now as wide as it needs to be to display the full string in each row.

Example 2: How to Use Format-Table with Width Parameter in PowerShell

We can also use the width parameter to specify that the column named Name should only show the first 8 characters of each string, while the DisplayName column should simply show the default number of characters:

PowerShell Format-Table control width

Notice that the Name column is cut off to only display 8 characters while the DisplayName column has an unchanged width.

Note: You can find the complete documentation for the Format-Table cmdlet in PowerShell here.

:/>  Установите сетевое соединение между несколькими компьютерами в локальной сети, в дополнение к подключению компьютера с Windows 8 (или 7) и ноутбука к Интернету

PowerShell: How to Sort a Table with Format-Table
PowerShell: How to Use Format-Table with No Header
PowerShell: How to Remove Elements from a Hash Table