0
0
PowerShellscripting~5 mins

Why PowerShell is object-oriented

Choose your learning style9 modes available
Introduction

PowerShell works with objects, not just text. This makes it easier to handle data and do complex tasks simply.

When you want to get detailed information about files or processes.
When you need to filter or sort data easily.
When you want to pass data between commands without losing structure.
When automating tasks that involve system settings or configurations.
When you want to use properties and methods directly on data.
Syntax
PowerShell
Get-Process | Get-Member

This command shows the properties and methods of the objects output by Get-Process.

Objects have properties (data) and methods (actions you can do).

Examples
Selects only the Name and Id properties from process objects.
PowerShell
Get-Process | Select-Object Name, Id
Stores a service object and shows its Status property.
PowerShell
$service = Get-Service -Name wuauserv
$service.Status
Gets the current date as an object and adds 5 days using a method.
PowerShell
$date = Get-Date
$date.AddDays(5)
Sample Program

This script gets the notepad process as an object. It then prints its name, ID, and start time using properties.

PowerShell
# Get a process object
$proc = Get-Process -Name notepad

# Show the process name and ID
Write-Output "Process Name: $($proc.Name)"
Write-Output "Process ID: $($proc.Id)"

# Show the process start time
Write-Output "Start Time: $($proc.StartTime)"
OutputSuccess
Important Notes

PowerShell objects keep data organized, unlike plain text.

You can use methods to perform actions on objects directly.

Using objects helps avoid errors when processing complex data.

Summary

PowerShell uses objects to handle data with properties and methods.

This makes scripting easier and more powerful.

Objects keep data structured and ready for automation tasks.