Course / 03 Command line / Lesson 19 of 19

Command Prompt versus PowerShell

Estimated time: 15 min reading · 15 min activity

Two terminal tabs can display the same folder and still interpret different command languages. The terminal provides the interface; its active shell reads your command. Identify that shell before copying a command from an example.

Command Prompt usually runs cmd.exe, whose builtin commands include dir. PowerShell uses cmdlets, commands designed for its shell, such as Get-ChildItem. Cmdlets can pass objects: structured values with named properties. A file object can have properties such as Name and Length.

Before you begin

Estimated time
15 min reading, 15 min activity. Setup and optional practice may take longer.
Where you work
Use the supplied Windows, Command Prompt and PowerShell examples in any browser, including mobile. You can finish from the printed cards if you do not have Windows. No installation, paid account, admin permission, registry edit, or policy change is needed for the card route. Optional extension: 10–15 minutes.
Without a lab
The page supplies the files, source and text records needed for the activity. Without a shell, follow the numbered steps on paper, label each result as predicted, and use the separate evidence supplied by the question. Running commands can wait until your lab is available. Reading works without JavaScript. Answer checking needs JavaScript and a secure context, such as HTTPS; saving a correct result also needs usable browser storage. Missing tools, managed or mobile hosts, or a deferred guest setup never require buying a service. Keep owned lab files for review; do not use broad deletion.

After this lesson you can:

  • Identify the interpreter from command and shell evidence.
  • Explain a PowerShell file object's Name property.
  • Map a harmless listing task and consolidate Stage 03 boundaries.

01Example

A fictional folder contains alpha.txt, beta.txt and a subfolder drafts. Each command form selects files while excluding the folder. Read them as alternatives for their respective shells. The output is predicted; its order and formatting can vary.

PowerShell command:
Get-ChildItem -LiteralPath . -File | Select-Object Name
Predicted Name values:
alpha.txt, beta.txt

cmd command:
dir /b /a-d
Predicted text lines:
alpha.txt
beta.txt

Neither listing changes the files.

02Property selection differs from text matching

Get-ChildItem lists items at a location. In -LiteralPath ., the dot names the current directory and LiteralPath treats that path as given. -File selects files rather than subdirectories. The pipeline sends those file objects to Select-Object Name, which retains their Name property.

A property is a named field of an object. Choosing Name does not search for text containing the letters Name. Choosing Length instead selects another field. The shell can display the results as a table, but the values passed between these cmdlets are structured objects.

In cmd, dir /b /a-d prints a bare text listing while excluding directories. /b requests the bare form; /a-d selects entries without the directory attribute. Here the same files appear in both listings even though the two pipelines use different data models.

The Bash examples use byte or text streams. PowerShell can also interact with native programs whose output behaves differently from file objects. Determine the data from the actual commands, not just the | symbol. Aliases, alternate short command names, can also resolve differently across shells; these examples use explicit cmdlet names.

The same file names can be obtained through object-property projection or bare text listing; source entries stay unchanged.Model. A teaching model drawn by hand. It shows the idea, not real tool output.

Read the full explanation below.

Fixed folderPowerShell Name projectioncmd bare text

All supplied entries remain stored.

Immutable supplied teaching corpus

NameEntry type
alpha.txtfile
beta.txtfile
draftsdirectory
Selected view

Result

alpha.txt  file
beta.txt  file
drafts  directory

The folder contains two files and a directory; neither command changes it.

Follow the explanation

  1. The folder contains two files and a directory; neither command changes it.
  2. -File excludes drafts; Select-Object Name selects object property values alpha.txt and beta.txt.
  3. /a-d excludes the directory and /b produces bare text names.
Read every state and value

1. The folder contains two files and a directory; neither command changes it.

View
source
Rows shown
alpha.txt · file · beta.txt · file · drafts · directory
Highlighted Cell Refs
None
Result rows
Source Row: alpha.txt · file; Cells: alpha.txt · file · Source Row: beta.txt · file; Cells: beta.txt · file · Source Row: drafts · directory; Cells: drafts · directory · directory

2. -File excludes drafts; Select-Object Name selects object property values alpha.txt and beta.txt.

View
PowerShell Name projection
Rows shown
alpha.txt · file · beta.txt · file
Highlighted Cell Refs
Row: alpha.txt · file; Column: Name · Row: beta.txt · file; Column: Name
Result rows
Source Row: alpha.txt · file; Cells: alpha.txt · Source Row: beta.txt · file; Cells: beta.txt

3. /a-d excludes the directory and /b produces bare text names.

View
cmd
Rows shown
alpha.txt · file · beta.txt · file
Highlighted Cell Refs
Row: alpha.txt · file; Column: Entry type · Row: beta.txt · file; Column: Entry type
Result rows
Source Row: alpha.txt · file; Cells: alpha.txt · Source Row: beta.txt · file; Cells: beta.txt
The same file names can be obtained through object-property projection or bare text listing; source entries stay unchanged.

03Try the listing comparison

First use a fresh paper case: a folder contains birch.txt, one subfolder drafts and maple.log. Predict which entries a file-only listing includes, then describe what changes when selecting Name rather than Length. Both files qualify regardless of extension; the directory does not.

The supplied cards below use a different folder, with alpha.txt and beta.txt. They provide the complete comparison for the numbered steps and optional live listing. The later question uses its own property selection. With no Windows shell, explain the object/text distinction from these printed cards and leave execution deferred.

Read file objects and their selected properties

A cmdlet is a PowerShell command. An object is a structured value with
named properties; Name and Length are file-item properties. Selecting
a property is different from finding text in a line. The display below
is a conceptual example rather than an actual folder observation.

Fixed folder contains alpha.txt, beta.txt and a subfolder drafts.
Get-ChildItem -LiteralPath . -File | Select-Object Name
Predicted display (order/format may vary):
Name
----
alpha.txt
beta.txt
Pipeline passes file objects; Name is a property. drafts is a directory
and excluded by -File. No file is changed by this listing.
Separate question pipeline: Get-ChildItem -File | Select-Object Length
Which shell passes objects with named properties? PowerShell or cmd

Download the complete conceptual PowerShell listing

Read a Command Prompt text listing

cmd interprets the command below. /b requests bare text names, while
/a-d excludes directories. Compare this text output with PowerShell
file objects. Both examples describe the same fictional folder.

Same fixed folder: alpha.txt, beta.txt, subfolder drafts.
dir /b /a-d
Predicted text lines (order may vary):
alpha.txt
beta.txt
/b requests bare listing; /a-d excludes directories.
This is a cmd builtin, not Bash ls or PowerShell's object pipeline.
No date/version banner or real personal directory output is claimed.

Download the same folder's conceptual cmd listing

  1. Label the fixed folder's two files and subfolder. Predict which items -File and /a-d include. Expected: only alpha.txt and beta.txt, not drafts.
  2. For the PowerShell card, identify objects and their Name property before the final display. For cmd, identify text lines. Explain why Select-Object is not grep for the word Name.
  3. If on owned Windows, open the specifically named PowerShell or Command Prompt app/tab, navigate through its UI or documented shell path to a known personal folder, and run only its matching listing. Use a known full quoted personal folder with Get-ChildItem -LiteralPath if unsure of PowerShell's current directory; cmd users can use dir /b /a-d with their quoted known folder path.
  4. Record actual filenames privately and the actual shell/version; outputs will differ from the fictional folder. With no Windows shell, trace the fixed cards and label execution deferred.
  5. Close the optional tab or retain the note. No files, policy or services were changed, so no cleanup operation is required.

04Windows module and Stage 03 evidence note

Combine the Windows case with the earlier lab notes in a short evidence note. Begin with path, system and shell before choosing syntax. In this case, either matching command lists oak.txt and pine.txt while excluding drafts. Explain how PowerShell objects differ from cmd text.

Check the Linux parts of your note: choose the correct class for mode 640, follow stdout into a replacement file, identify only a job you created, and distinguish repository information from installation. Explain why the reviewed note-list script reads its scoped tree. Keep SSH as a permission and identity checklist.

Finish by separating observations from paper predictions and naming any practical work still deferred. This combines the stage's reasoning without requiring Windows installation, a remote login or administrative changes.

Write one evidence note across the command-line stage

First identify the system and shell, then choose the matching syntax.
For each claim, name the supplied evidence, explain the operation and
state a limit. Distinguish observed results from paper predictions and
leave any actual Windows or remote connection work deferred.

Original case: Windows folder with oak.txt, pine.txt and folder drafts.
Task: list only files, then name the shell and kind of pipeline data.
A: cmd dir /b /a-d
B: PowerShell Get-ChildItem -File | Select-Object Name
Linux companion: owned note tree, mode 640 analyst/learners, one owned
sleep job, metadata-only apt refresh and a read-only note-list script.
Write a short evidence note mapping path/shell, role/mode, stdout/file,
process identity, package transaction and script effects. SSH labels are
for syntax only. Do not type Linux commands into cmd to test a guess.

Download the Windows and Stage 03 synthesis case

05Optional challenge

Allow about ten extra minutes. In the fresh birch.txt/maple.log case, predict selecting Length instead of Name. Explain how the selected properties change while the files themselves remain unchanged. You need no installation or execution-policy change.

06Fresh cases for the checks

Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.

Shell card A: supplied file objects for property selectionOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Current folder items, with complete properties needed here:
Name: ferry.txt   Type: file       Length: 18
Name: hills.log   Type: file       Length: 52
Name: old         Type: directory  Length: not supplied
Pipeline N: Get-ChildItem -LiteralPath . -File | Select-Object Name
Pipeline L: Get-ChildItem -LiteralPath . -File | Select-Object Length
Pipeline A: Get-ChildItem -LiteralPath . | Select-Object Name
Predict selected values only. Ignore display headers, spacing and order.
The items and commands are fictional; no live listing is recorded.

Shell card B: separate interpreter evidenceOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Case J: the shell runs Get-ChildItem -LiteralPath . -File | Select-Object Name.
        File objects flow between those cmdlets before display.
Case K: cmd.exe runs its builtin dir /b /a-d and prints bare text names.
Case M: Bash runs a reviewed printf command whose stdout is a text stream, not file objects.
These are separate sessions. Their terminal window appearance is not supplied.

Shell card C: independent harmless listing taskOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Current owned folder contains files coast.txt and valley.log, plus directory drafts.
Task: list only the files by name, without changing any entry.
Choose one command for a specifically identified PowerShell session and one for cmd.
Do not infer either shell from the appearance of its terminal tab.

Shell card D: a listing is not an access testOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

A supplied PowerShell prediction lists the Name values tide.txt and wind.log.
The command is Get-ChildItem -LiteralPath . -File | Select-Object Name.
No file-content read, write attempt, access-control rules or permission from an owner are supplied.
This is a printed prediction, not an observation of the learner's computer.

Shell card E: separate changed propertyOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

Fixed current folder: file trail.txt has Length 73; directory drafts has no Length value supplied.
Original selection: Get-ChildItem -LiteralPath . -File | Select-Object Name
Changed selection: Get-ChildItem -LiteralPath . -File | Select-Object Length
No item changes. Ignore display headers and spacing; predict only the one selected value.

07Explain a shell-specific listing

Optional self-check: describe how to choose a harmless file-only listing for an identified Windows shell and interpret its result. Explain what changes when selecting Name instead of Length.

Review your explanation: identify the interpreter from shell/command evidence; connect -File or /a-d to excluding directories; distinguish PowerShell object-property selection from cmd text; separate selected values from display formatting; and avoid inferring content access, authorization or local observations from a supplied list. This explanation is self-reviewed.

08Common mistakes

If a command is rejected or interpreted differently, identify cmd versus PowerShell before editing syntax. A terminal application's appearance does not establish its active interpreter.

If Name is mistaken for text to match, trace file objects into Select-Object. Property selection chooses a structured field; it is not grep's text-search operation.

If your live listing contains different names, use that as a private observation, not a substitute for the question's supplied card. Use the commands and property meanings to interpret the supplied case.

References

  • Microsoft: Get-ChildItem

    File-system listing, -File and item properties. Online documentation may default to a newer PowerShell; compare installed Windows PowerShell 5.1 or PowerShell 7 behavior on your own machine.

  • Microsoft: Select-Object

    Property selection versus object display. Check the PowerShell version on your own machine; Name/Length examples here are original.

  • Microsoft: about_Pipelines

    Object flow between cmdlets and distinctions involving native programs. Not every command using | returns file objects.

  • Microsoft: dir

    Command Prompt listing syntax, /b and /a attributes. Optional listing is read-only and scoped to an owned folder.

  • Microsoft: cmd

    Command Prompt interpreter and command syntax. Windows release, configuration, and prompts can differ. This lesson's printed cards are the evidence.

Next is the first lesson of Code.