Everything in PowerShell is already or becomes a .NET object. Therefore, you should be familiar with how to handle and analyze them. Objects are easiest to visualize as text tables, but keep in mind that the entries themselves can also be objects.
- PowerShell modules return objects of a specific type
- external programs return an array of lines
Object[]
(Array von Textzeilen) zurück.
An understanding of pipelinesis required.
Inspect result object
See object’s type and properties
- in terminals, you may abbreviate with
$drives | gm
Count objects
Count elements or file lines
Add index the each results
Narrow down a result
Select specific indexes
Select a range at the beginning, end or with specific indexes at the beginning
Select duplicates only once
Condition expression(s) to be selected
- Learn operators using:
Get-Help about_Comparison_Operators
- in terminals, you may abbreviate with
$drives | where Name -match "vpn"
Select specific properties of a result
View all properties
Select existing properties
Select a precalculated property
Select a property to be calculated dynamically during readout
- in terminals, you may abbreviate with
$files | select Name, @{name="Size in MB"; expr={[Math]::Round($_.Length / 1MB, 2)}}
Sort a result
Sort ascending / default direction
Specify sorting direction
- in terminals, you may abbreviate with
$drives | sort @{expr="Version"; desc=$True}, Name
Sources:
- 2023-03-19: about Calculated Properties - PowerShell | Microsoft Learn
- 2023-03-19: Add a calculated property with Select-Object in PowerShell – 4sysops
- 2023-03-10: Select-Object (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
- 2023-03-10: Add-Member (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Learn
- 2023-03-10: Ultimate Guide to Using PowerShell Add-Member Cmdlet - i Love PowerShell
- 2023-03-10: String.PadRight Methode (System) | Microsoft Learn
Related:
Tags:
PowerShell Objects - Handle, Import, Export, Filter and RegEx query objects