PowerShell

How to preview part of PowerShell array

How to preview part of PowerShell array

As I’m working in PowerShell ISE, I would like to take a quick look at my results in an array or hash table. Here is how to preview part of that.

Here is the array $p with all the Windows svchost processes that I will use for demonstration.

$p = Get-Process svchost

The first item of an array. Indexation starts at 0.

$p[0]

First 5 items of the array.

$p[0..5]

Last item of the array.

$p[-1]

Last 5 items of the array.

$p[-5..-1]

Alternatively, you can preview your array in Powershell by using select.

$p | select -First 5

$p | select -Last 5

Most of the time, I like to generate a preview of the array in the PowerShell console. Here are two of the PowerShell ISE shortcuts that I’m using to switch to console and back to the script pane.

Ctrl + D – go to the PowerShell console
Ctrl + I – go to the PowerShell script pane

 

Execute Windows CMD command (PowerShell) from R script

 




0 comments on “How to preview part of PowerShell array

Leave a Reply

Your email address will not be published. Required fields are marked *