PowerShell objects tutorial explains how to work with objects in PowerShell.
last modified February 20, 2025
In this article, we will explore objects in PowerShell.
PowerShell is an object-oriented scripting language. Everything in PowerShell is an object, including variables, strings, and system components.
You can create custom objects using New-Object or [PSCustomObject].
custom_object.ps1
$obj = New-Object PSObject -Property @{ Name=“Alice”; Age=30 } Write-Output $obj
You can access object properties using dot notation.
get_properties.ps1
$process = Get-Process | Select-Object -First 1 Write-Output $process.Name
You can modify object properties after creation.
modify_object.ps1
$obj = [PSCustomObject]@{ Name=“Bob”; Age=25 } $obj.Age = 26 Write-Output $obj
You can filter objects using Where-Object.
filter_objects.ps1
$processes = Get-Process | Where-Object { $_.CPU -gt 10 } Write-Output $processes
You can sort objects using Sort-Object.
sort_objects.ps1
$processes = Get-Process | Sort-Object -Property CPU -Descending Write-Output $processes
You can select specific properties using Select-Object.
select_properties.ps1
$processes = Get-Process | Select-Object Name, CPU Write-Output $processes
In this article, we have explored objects in PowerShell.
My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.
List all PowerShell tutorials.