- Courses
- 💻Programming Languages
- 🪟PowerShell
- Foundations of PowerShell
- Working with Objects
On this page
PowerShell Objects – Properties, Methods, and Custom Objects
By Enrico Hochkoeppler
Web Developer & TutoriaLibre Founder
PowerShell is an object-oriented scripting language. Every value produced by a command is a .NET object — a structured piece of data with typed properties and callable methods. Text appears only at the very end of a pipeline, as a rendering of the final object's data. Understanding what objects are, how to discover their structure, how to manipulate them, and how to create your own is the foundation of effective PowerShell scripting.
What Is an Object?
An object is a unit of structured data. It combines two things:
- Properties — data values that describe the object's state: a name, a number, a date, a status
- Methods — actions the object can perform: stop a service, close a window, calculate a hash
Every object in PowerShell belongs to a .NET type — a class defined in the .NET runtime that specifies exactly which properties and methods the object has. The type System.Diagnostics.Process defines every process object. The type System.ServiceProcess.ServiceController defines every service object.
When you run Get-Process, PowerShell does not return text describing processes. It returns actual System.Diagnostics.Process objects — the same objects that a C# or VB.NET application would work with. The text you see on screen is a rendering of those objects produced by PowerShell's output formatting system.
Discovering Object Structure with Get-Member
Get-Member is the primary tool for discovering the structure of any object in PowerShell. Pipe any command's output to it to see the type name, all properties, and all methods:
Get-Service -Name w32time | Get-Member
The first line of the output is the most important:
TypeName: System.ServiceProcess.ServiceController
This tells you the exact .NET type. Everything that follows is a member of that type.
Name MemberType Definition
---- ---------- ----------
Close Method void Close()
Continue Method void Continue()
Pause Method void Pause()
Start Method void Start()
Stop Method void Stop()
CanPauseAndContinue Property bool CanPauseAndContinue {get;}
CanStop Property bool CanStop {get;}
DisplayName Property string DisplayName {get;set;}
ServiceName Property string ServiceName {get;set;}
StartType Property System.ServiceProcess.ServiceStartMode
Status Property System.ServiceProcess.ServiceControllerStatus
Filtering Get-Member output
By default, Get-Member lists all member types. Use -MemberType to filter:
# Properties only
Get-Service -Name w32time | Get-Member -MemberType Property
# Methods only
Get-Service -Name w32time | Get-Member -MemberType Method
# All property-like members (properties, alias properties, script properties)
Get-Process | Get-Member -MemberType *Property
Member types explained
Get-Member output includes several member types that appear in the results:
MemberTypeWhat it isPropertyA standard read or read-write data fieldAliasPropertyA short alias for another property (e.g., Name = ProcessName)ScriptPropertyA property computed by a PowerShell script block at access timeNotePropertyAn added property with a static value (used in custom objects)MethodA callable .NET methodScriptMethodA method implemented in PowerShell (e.g., ToString)
Understanding these types prevents confusion when you see properties like CPU on a process object — CPU is a ScriptProperty that calls TotalProcessorTime internally, not a raw .NET field.
Properties: Reading and Writing Object Data
Reading properties with dot notation
Access any property on an object using a dot followed by the property name:
$service = Get-Service -Name w32time
$service.Status # Running
$service.DisplayName # Windows Time
$service.CanStop # True
In a pipeline, use $_ (the current object) to access properties:
Get-Service | Where-Object { $_.Status -eq 'Running' }
Get-Process | ForEach-Object { "$($_.Name) uses $([math]::Round($_.WorkingSet64 / 1MB, 1)) MB" }
Default display vs all properties
PowerShell displays only a subset of properties by default. When a command produces four properties or fewer, it formats them as a table. When it produces five or more, it switches to a list. Either way, it only shows the properties defined in the formatting configuration for that type — not all available properties.
To see all properties on an object, pipe to Select-Object *:
Get-Service -Name w32time | Select-Object *
Output reveals many properties not shown by default:
Name : w32time
RequiredServices : {}
CanPauseAndContinue : False
CanShutdown : True
CanStop : True
DisplayName : Windows Time
MachineName : .
ServiceName : w32time
ServicesDependedOn : {}
StartType : Manual
Status : Running
ServiceType : Win32OwnProcess, Win32ShareProcess
Format-List * also shows all properties, but unlike Select-Object *, it does not preserve the structured object — it converts it to display text. Use Select-Object * when you need to continue working with the data; use Format-List * only for terminal display.
Writing to properties with dot notation
Properties marked {get;set;} in Get-Member are writable. Assign a new value using the same dot notation:
$process = Get-Process -Name notepad
$process.PriorityClass = [System.Diagnostics.ProcessPriorityClass]::High
Not all properties are writable. Properties marked {get;} only are read-only. Attempting to write to a read-only property throws a SetValueException.
Methods: Performing Actions on Objects
Methods are actions an object can perform, called with parentheses. Some take no arguments; others require one or more:
# No arguments
(Get-Service -Name w32time).Stop()
# With an argument — WaitForStatus waits until the service reaches a state
(Get-Service -Name w32time).WaitForStatus([System.ServiceProcess.ServiceControllerStatus]::Running, [TimeSpan]::FromSeconds(30))
Methods vs cmdlets
Methods give you direct access to .NET functionality, but dedicated cmdlets are almost always preferable when one exists. Cmdlets provide:
-WhatIfand-Confirmsupport for safe testing before making changes-PassThruto return output when the default is silent- Consistent error handling through the PowerShell error system
- Integration with
-Verboseand-Debugstreams
# Using a method — no safety features, no output by default
(Get-Service -Name w32time).Stop()
# Using a cmdlet — supports -WhatIf, -PassThru, error handling
Stop-Service -Name w32time -WhatIf
Stop-Service -Name w32time -PassThru # returns the updated service object
Use methods when no corresponding cmdlet exists. For example, Get-SqlAgentJob in the SqlServer module has no Set-SqlAgentJob cmdlet — you must use the method. In all other cases, prefer the cmdlet.
Creating Custom Objects
Producing your own objects with exactly the properties you need — rather than filtering properties from an existing object — makes scripts more readable, enables clean pipeline chaining, and produces structured output that callers can work with as data.
[PSCustomObject] cast — the recommended approach
The [PSCustomObject] cast on a hash table is the fastest and most idiomatic way to create a custom object in modern PowerShell:
$server = [PSCustomObject]@{
Name = "srv-web-01"
IPAddress = "10.0.0.5"
OS = "Windows Server 2022"
IsOnline = $true
LastChecked = Get-Date
}
The result is a PSCustomObject with five named properties, accessible via dot notation:
$server.Name # srv-web-01
$server.IsOnline # True
$server.LastChecked # current date and time
It passes through the pipeline exactly like any other object:
$servers | Where-Object IsOnline -eq $true | Select-Object Name, IPAddress
New-Object PSObject — the older approach
New-Object PSObject -Property @{} predates the [PSCustomObject] cast and is significantly slower. You may encounter it in older scripts:
# Older — slower and more verbose
$server = New-Object PSObject -Property @{
Name = "srv-web-01"
IPAddress = "10.0.0.5"
}
Use [PSCustomObject]@{} in all new code. The only reason to use New-Object PSObject is when maintaining a script targeting PowerShell 2.0, which predates the cast syntax.
Property order in custom objects
The [PSCustomObject] cast preserves the insertion order of properties — the order you declare them in the hash table is the order they appear in output. This is unlike regular hash tables, which have no guaranteed order. This makes [PSCustomObject] suitable for producing table-formatted output where column order matters.
Modifying Objects: Add-Member
Add-Member adds new properties or methods to an existing object. This is useful when you need to attach computed data or metadata to an object from a cmdlet without replacing it with a custom object:
Adding a NoteProperty
$process = Get-Process -Name notepad
# Add a static property
$process | Add-Member -MemberType NoteProperty -Name "Category" -Value "Editor"
$process.Category # Editor
Adding a ScriptProperty
A ScriptProperty is computed each time it is accessed, rather than stored statically:
$process | Add-Member -MemberType ScriptProperty -Name "MemoryMB" -Value {
[math]::Round($this.WorkingSet64 / 1MB, 1)
}
$process.MemoryMB # current memory in MB, calculated live
Inside a ScriptProperty script block, $this refers to the object the property is attached to.
Adding properties to pipeline output
Use -PassThru to make Add-Member return the modified object so it can continue through the pipeline:
Get-Process |
Where-Object WorkingSet64 -gt 100MB |
ForEach-Object {
$_ | Add-Member -MemberType NoteProperty -Name "MemoryMB" -Value ([math]::Round($_.WorkingSet64 / 1MB, 1)) -PassThru
} |
Select-Object Name, MemoryMB |
Sort-Object MemoryMB -Descending
Creating Arrays of Custom Objects
A common pattern is building a collection of custom objects inside a loop, then working with the entire collection as a pipeline-compatible array:
$report = foreach ($service in (Get-Service)) {
[PSCustomObject]@{
Name = $service.DisplayName
Status = $service.Status
StartType = $service.StartType
CanStop = $service.CanStop
}
}
# $report is now an array of PSCustomObjects
$report | Where-Object Status -eq Stopped | Sort-Object Name
$report | Export-Csv -Path "C:\Reports\services.csv" -NoTypeInformation
The foreach loop returns each [PSCustomObject] as output, which PowerShell collects into an array automatically. This is faster and cleaner than building an array with += in a loop (which creates a new array on every iteration).
Select-Object with Calculated Properties
Select-Object can create new properties on the fly using hash table expressions, producing shaped objects without modifying the originals:
Get-Process |
Select-Object Name, Id,
@{ Name = "MemoryMB"; Expression = { [math]::Round($_.WorkingSet64 / 1MB, 1) } },
@{ Name = "CPURounded"; Expression = { [math]::Round($_.CPU, 2) } } |
Sort-Object MemoryMB -Descending |
Select-Object -First 10
Each hash table in the property list has a Name key (the new property name) and an Expression key (a script block that computes the value). The result is a new PSCustomObject for each input, with only the properties you defined.
Practical Examples
Build a server inventory report
$servers = "srv-01", "srv-02", "srv-03"
$inventory = foreach ($name in $servers) {
[PSCustomObject]@{
Name = $name
Online = (Test-Connection -ComputerName $name -Count 1 -Quiet)
CheckedAt = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
}
$inventory | Format-Table -AutoSize
$inventory | Export-Csv "inventory.csv" -NoTypeInformation
Enrich process objects with department metadata
$knownProcesses = @{
"chrome" = "Browser"
"code" = "Development"
"notepad" = "Editor"
"outlook" = "Email"
}
Get-Process |
Where-Object { $knownProcesses.ContainsKey($_.Name) } |
Select-Object Name, Id,
@{ Name = "Department"; Expression = { $knownProcesses[$_.Name] } },
@{ Name = "MemoryMB"; Expression = { [math]::Round($_.WorkingSet64 / 1MB, 1) } }
Common Mistakes to Avoid
Accessing properties on $null. When a command returns nothing — Get-Service -Name "nonexistent" returns $null — accessing a property on the result silently returns $null without throwing an error. This produces silent bugs. Always check for $null before accessing properties: if ($null -ne $result) { $result.Status }.
Using New-Object PSObject instead of [PSCustomObject]. The cast syntax is faster, cleaner, and handles property ordering automatically. Reserve New-Object PSObject for legacy scripts only.
Placing format cmdlets in the middle of a pipeline. Format-Table, Format-List, and Format-Wide convert objects to display text. Any command after a format cmdlet receives that text, not the original object. Formatting is always the last stage.
Calling methods when a cmdlet exists. Methods bypass -WhatIf, -PassThru, and structured error handling. Use the corresponding cmdlet unless no dedicated cmdlet exists.
Not using Get-Member to discover properties. The default table display shows only a subset of properties. Always pipe to Get-Member or Select-Object * to discover the full property set before writing code that accesses specific properties.
Practice Commands
# Discover object types and members
Get-Process | Get-Member
Get-Service | Get-Member -MemberType Property
Get-ChildItem | Get-Member -MemberType *Property
# See all properties (not just the default display)
Get-Service -Name w32time | Select-Object *
Get-Process -Name powershell | Select-Object *
# Access properties and call methods
$svc = Get-Service -Name w32time
$svc.Status
$svc.DisplayName
$svc.CanStop
# Create a custom object
$item = [PSCustomObject]@{
Name = "Test"
Value = 42
Date = Get-Date
}
$item | Get-Member
# Add a property to an existing object
$proc = Get-Process -Name powershell
$proc | Add-Member -MemberType NoteProperty -Name "Monitored" -Value $true -PassThru | Select-Object Name, Monitored
# Build an array of custom objects
$data = 1..5 | ForEach-Object {
[PSCustomObject]@{ Number = $_; Square = $_ * $_ }
}
$data | Format-Table
$data | Where-Object Square -gt 10
Found this helpful? Share the knowledge...
... or support this project to keep it alive!
Previous
Commands, Cmdlets and the Pipeline
Next
Providers and the PowerShell Drive Model
-
What Is an Object?
-
Discovering Object Structure with
Get-Member- Filtering
Get-Memberoutput - Member types explained
- Filtering
-
Properties: Reading and Writing Object Data
- Reading properties with dot notation
- Default display vs all properties
- Writing to properties with dot notation
-
Methods: Performing Actions on Objects
- Methods vs cmdlets
-
Creating Custom Objects
[PSCustomObject]cast — the recommended approachNew-Object PSObject— the older approach- Property order in custom objects
-
Modifying Objects:
Add-Member- Adding a
NoteProperty - Adding a
ScriptProperty - Adding properties to pipeline output
- Adding a
-
Creating Arrays of Custom Objects
-
Select-Objectwith Calculated Properties -
Practical Examples
- Build a server inventory report
- Enrich process objects with department metadata
-
Common Mistakes to Avoid
-
Practice Commands
