0
0
PowerShellscripting~10 mins

Why PowerShell is object-oriented - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why PowerShell is object-oriented
PowerShell Command Runs
Returns Objects, not Text
Objects Have Properties & Methods
You Can Access & Use Them Directly
Enables Powerful Automation & Scripting
PowerShell commands return objects with properties and methods, letting you work with structured data directly, unlike plain text output.
Execution Sample
PowerShell
Get-Process | Select-Object -First 1 | Format-List -Property Name,Id
$proc = Get-Process | Select-Object -First 1
$proc.Name
$proc.Id
This code gets one process object, shows its Name and Id, then accesses those properties directly.
Execution Table
StepActionCommand/ExpressionResult/Output
1Get first process objectGet-Process | Select-Object -First 1Returns a Process object with many properties
2Display Name and Id propertiesGet-Process | Select-Object -First 1 | Format-List -Property Name,IdShows Name and Id as text output
3Assign process object to variable$proc = Get-Process | Select-Object -First 1Variable $proc holds the Process object
4Access Name property$proc.NameOutputs the process name as string
5Access Id property$proc.IdOutputs the process ID as number
💡 All steps complete; demonstrated object retrieval and property access
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5
$procnullProcess object (e.g. Name='powershell', Id=1234)Same object, Name property accessedSame object, Id property accessed
Key Moments - 3 Insights
Why does $proc.Name give a simple string instead of text output?
Because $proc is an object with a Name property; accessing $proc.Name returns that property's value directly, as shown in execution_table step 4.
How is PowerShell output different from traditional command-line text output?
PowerShell outputs objects with properties and methods, not just plain text lines. This is shown in step 1 where Get-Process returns an object, not text.
Can you use methods on the objects returned by PowerShell commands?
Yes, objects have methods you can call directly, enabling powerful scripting. This is implied by the object-oriented nature shown in the concept flow.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what type of data is stored in $proc after step 3?
AA plain text string
BA Process object with properties
CA number representing process ID
DAn array of strings
💡 Hint
Check the 'Result/Output' column in step 3 of the execution_table
At which step does the script access the Name property of the process object?
AStep 1
BStep 2
CStep 4
DStep 5
💡 Hint
Look for '$proc.Name' in the 'Command/Expression' column of the execution_table
If PowerShell returned plain text instead of objects, what would happen to $proc.Name access?
AIt would cause an error because text has no properties
BIt would still work the same
CIt would return the whole text output
DIt would return null silently
💡 Hint
Refer to the key_moments section explaining object vs text output
Concept Snapshot
PowerShell commands return objects, not plain text.
Objects have properties and methods you can access directly.
This lets you work with structured data easily.
Use variables to hold objects and access their members.
This object-oriented design enables powerful automation.
Full Transcript
PowerShell is object-oriented because its commands return objects with properties and methods instead of plain text. For example, Get-Process returns a process object. You can assign this object to a variable like $proc and then access properties such as $proc.Name or $proc.Id directly. This is different from traditional shells that return text output only. Working with objects allows you to write more powerful and flexible scripts by manipulating structured data easily. The execution steps show getting a process object, displaying some properties, and accessing them through variables. This object-oriented approach is a core reason PowerShell is powerful for automation.