LESSON 1 OF 4
Discover commands and inspect their objects
Commands have a discoverable contract
PowerShell commands commonly use a verb-noun name. Get-Process communicates an inspection operation; Stop-Process communicates a change. A reassuring verb is a useful clue, but it is not a security guarantee. A script or function can use an innocent name and still change files or send data. Inspect the implementation and documentation before running unfamiliar code.
Start with discovery:
$PSVersionTable.PSVersion
Get-Command Get-Process
Get-Help Get-Process -Examples
Get-Process | Select-Object -First 3 -Property Id, ProcessName
Get-Process | Get-Member
Get-Command tells you what command PowerShell resolves, including whether it is a cmdlet, function, alias or application. Name resolution matters when a profile or imported module defines the same name. Get-Help describes the parameters and behavior. Some installations have incomplete local help; the absence of examples does not mean that a parameter is safe to invent. Consult the matching official documentation when local help is unavailable.
The final command inspects the type and members of the emitted process objects. A process row on screen is a presentation of an object. Its properties can include values not shown by the default display. Do not parse the spaces in the table to obtain a process name or identifier. Select the property directly.
Run the examples and record three observations: your PowerShell edition, the command type for Get-Process, and the type shown by Get-Member. Process names and identifiers differ between machines, so this exercise has no fixed process list. A successful result shows that you can explain the object structure without treating the displayed table as its storage format.
Variables, strings and explicit conversion
A variable name begins with $. Assignment stores a value or a collection, rather than a text line from a terminal. Values have types. The following examples demonstrate a difference that matters when reading CSV:
$left = '2'
$right = '3'
$left + $right
[int]$left + [int]$right
$left.GetType().Name
$machine = 'APP01'
"Checking $machine"
'Checking $machine'
The expected first two results are 23 and 5. A CSV field containing digits is still text until validated and converted. Double-quoted strings expand variables; single-quoted strings preserve the dollar sign and name. Use this distinction deliberately when building an error message or documenting a literal command.
A cast can fail. [int]'offline' cannot provide a meaningful service count. A cast can also accept representations that your business rule should reject. The language's ability to convert a value and the report's decision to accept it are separate questions. Our report will first check that an uptime field contains a non-negative whole number. Only then will it convert the field.
Properties are a better interface than columns on screen
Create a small object:
$item = [pscustomobject]@{
Host = 'APP01'
Service = 'BackupAgent'
Status = 'Running'
UptimeHours = 12
}
$item.Host
$item | Select-Object Host, Service, Status
$item | Get-Member
The property names form the report's contract. A consumer can select Host even if a terminal is too narrow to display every property. A property called UptimeHours communicates a unit; a property called Value would force the reader to infer the unit from surrounding prose. Good naming reduces interpretation errors.
An ordered collection of property names is useful for export. Do not rely on a screenshot's column order or on the current console width. The final report will explicitly select its columns before writing CSV.
Practise before proceeding
Make a second object for APP02, service BackupAgent, status Stopped, and uptime 0. Predict whether printing the object will prove that the real service is stopped. It will not: you have created a fixture, not inspected a live system. Label it as synthetic evidence.
Change the status to lower-case running. Record whether comparing it with Running changes the result. PowerShell's usual string equality operators are case-insensitive; case-sensitive variants such as -ceq exist. Our report will normalize accepted status names so that the output is consistent. Normalization must not make an unsupported status such as StartingMaybe valid.
Reasoning model
A PowerShell pipeline carries objects until you deliberately format or serialize them. Keep selection, calculation and filtering before presentation. CSV values commonly enter as text, so validate and convert numeric fields before arithmetic. Define thresholds precisely: “less than 10%” differs from “10% or less.” Missing or zero capacity is not a healthy result; represent invalid input separately so the report cannot silently convert absence into reassurance.
YOUR NEXT STEP
Keep building your skills
No directly related CogniSkill book is mapped to this course yet. Continue with the free learning, or compare the publishing catalogue by your next goal.
Explore books by topic and goal →Sign in to save lesson completion. Reading position is separate from completion.
Practice notes — your working space
Save predictions, outputs and explanations as you work. Notes stay on this browser, not your account; people sharing this browser can access them. Avoid passwords and sensitive data. Export to keep a portable copy, or clear your notes before leaving a shared device.
How was this lesson?
Help us improve this lesson.