1 of 25

COMMAND-LINE INTERPRETER AND POWERSHELL ENVIRONMENT IN WINDOWS.

2 of 25

INTRODUCTION

Definition of a command interpreter: �A command interpreter is a program that accepts text commands from the user, processes them, and performs the corresponding operations in the operating system. It allows interaction with the system without a graphical interface.

Why do we need CLI (Command Line Interface)?

  1. Flexibility and power – The CLI provides more capabilities than the GUI.
  2. Automation – performing repetitive tasks using scripts.
  3. System Management – Advanced control over OS settings.
  4. Working on remote servers – many server operating systems operate without a graphical interface.
  5. Speed of operation – commands are executed faster than similar operations via the GUI.

The CLI is used by administrators, developers, and advanced users to effectively interact with the operating system.

3 of 25

A BRIEF OVERVIEW OF THE WINDOWS COMMAND PROMPT (CMD.EXE)

History and evolution

The Windows command line ( cmd.exe ) has a long history and evolution:

  • 1970s – development of the first MS-DOS command shell (Command.com).
  • 1981 – MS-DOS is released with simple text commands.
  • 1993 – Windows NT is released with a new shell , cmd.exe , replacing Command.com.
  • 2000s – Improved cmd.exe, but with limited functionality.
  • 2006 – PowerShell was released , which greatly expanded the command-line capabilities of Windows.

4 of 25

A BRIEF OVERVIEW OF THE WINDOWS COMMAND PROMPT (CMD.EXE)

Main features of cmd.exe

  1. Executing commands to work with files and directories
    • View folder contents: dir
    • Navigate between folders: cd
    • Copying files: copy
    • Deleting files: del
  2. Working with processes and tasks
    • View running processes: tasklist
    • Terminating processes: taskkill
  3. User and system management
    • Creating and deleting users: net user
    • Changing passwords: no user username *
  4. Network commands
    • Checking network connection: ping
    • View IP address: ipconfig
  5. Scripts and automation
    • Run .bat files to automatically execute commands.

While cmd.exe remains relevant, it lacks the capabilities of PowerShell , especially in automation and system management.

5 of 25

CMD

1. Working with files and directories

The command line allows you to perform basic operations with files and folders:

6 of 25

CMD

2. Network commands

Commands for diagnosing and managing network connections:

7 of 25

CMD

3. Managing users and processes

These commands allow you to effectively manage files, network, users, and processes in Windows using the command line.

8 of 25

CMD

  • While cmd.exe remains a useful tool, it has a number of significant limitations that have led to the need for an alternative in the form of PowerShell .

BASIC LIMITATIONS OF CMD

  • Limited functionality
  • cmd.exe only works with text strings and does not support full object handling.
  • There are no built-in commands for working with the registry, processes, or services without using additional utilities.
  • Lack of object-oriented approach
  • All information in cmd.exe is presented as lines.
  • To process data, you have to use utilities like find , for , grep , which complicates the analysis of information.
  • Poor automation support
  • Scripts in Batch files (.bat , .cmd ) have limited capabilities.
  • There is no support for modularity , working with variables, or powerful control structures.

9 of 25

BASIC LIMITATIONS OF CMD

  1. Lack of integration with .NET and Windows APIs
    • You can't use the powerful features of .NET, WMI (Windows Management Instrumentation ), and the Windows API in cmd.exe .
  2. Uncomfortable syntax and limited command capabilities
    • It is difficult to combine commands and control their output
    • Running complex scripts requires third-party utilities and batch files.
  3. Poor support for working with remote systems
    • cmd.exe does not provide convenient tools for administering remote computers.
    • In modern systems, administration often requires working through remote consoles (for example, PowerShell Remoting ).

10 of 25

WHY WAS AN ALTERNATIVE NEEDED?

All of these limitations led Microsoft to develop PowerShell – a powerful Windows administration tool that: �✅ Supports object-oriented design. �✅ Allows the use of .NET and WMI. �✅ Features a sophisticated scripting and modularity system. �✅ Provides tools for automating administration and working with remote systems.

PowerShell has become a powerful replacement for the outdated cmd.exe and is widely used by administrators and developers on modern Windows systems.

11 of 25

POWERSHELL : OVERVIEW AND DIFFERENCES FROM CMD

What is PowerShell ?

PowerShell is a powerful command shell and scripting language developed by Microsoft for task automation and Windows administration. Unlike the traditional command line ( cmd.exe ), PowerShell uses an object-oriented approach and allows for more efficient use of system resources.

🔹 Developed on the .NET Framework �🔹 Processes objects, not just text �🔹 Has a flexible system of modules and cmdlets �🔹 Allows you to automate complex administrative tasks �🔹 Supports working with remote systems

12 of 25

KEY DIFFERENCES BETWEEN POWERSHELL AND THE COMMAND PROMPT (CMD)

Characteristic

CMD

PowerShell

Based on

Text processing

Object Model (.NET)

Data type

Only lines

Objects that support methods and properties

Teams

Simple commands (dir, copy)

Powerful Cmdlets (Get-Process, Get-Service)

Scripts

Batch files (.bat, .cmd)

PowerShell scripts (.ps1)

Automation

Limited

Full-fledged scripts with loops and logic

Access to the system

Only basic functions

Access to Windows API, WMI, registry

Working with remote systems

No built-in support

PowerShell Remoting (WS-Man, SSH)

Scope of application

Local commands

Administration, automation

13 of 25

EXAMPLE COMMANDS IN CMD AND POWERSHELL

PowerShell returns objects with detailed information that can be filtered and sorted.

📌 Example 2: Deleting files older than 30 days �🔹 CMD (no built-in solution, need a forfiles script )

forfiles /p C:\Logs /s /m *.* /d -30 /c " cmd /c del @file"

🔹 PowerShell (one line)

Get- ChildItem C:\Logs -Recurse | Where-Object {$_. LastWriteTime - lt (Get-Date). AddDays (-30)} | Remove-Item

PowerShell makes this more convenient and powerful.

14 of 25

POWERSHELL

PowerShell is a powerful tool for managing Windows, offering several advantages over the classic CMD command line. Key features include an object-oriented approach , file and process management , and task automation .

1. Object-oriented approach

Unlike cmd.exe , which only processes strings, PowerShell works with objects that have properties and methods. This makes it more flexible and convenient.

Example: Getting a list of processes

🔹 CMD

tasklist

The output will be text and the data will be difficult to process.

🔹 PowerShell

Get-Process

PowerShell returns objects that can be filtered, sorted, and processed. For example, sorting by CPU usage:

Get-Process | Sort-Object CPU -Descending | Select-Object -First 5

đź’ˇ Advantage : you can work with the results as objects, not just text.

15 of 25

POWERSHELL

2. Working with files and processes

PowerShell provides convenient cmdlets for managing files and processes.

Files and directories

Deleting files older than 30 days

Get- ChildItem C:\Logs -Recurse | Where-Object {$_. LastWriteTime - lt (Get-Date). AddDays (-30)} | Remove-Item

16 of 25

POWERSHELL

3. Task automation

PowerShell supports scripts (.ps1 scripts) , loops, conditions, and remote systems, making it a powerful automation tool.

Example: Automatic file backup

The script copies all files from C:\Source to D:\Backup , adding the date to the folder name:

$Date = Get-Date -Format "yyyy-MM-dd"

$BackupPath = "D:\Backup\$Date"

New-Item -ItemType Directory -Path

$BackupPath Copy-Item -Path "C:\Source\*" -Destination $BackupPath -Recurse

Automatically running scripts

scheduled execution of PowerShell scripts via Task Scheduler , which is convenient for administration.

17 of 25

POWERSHELL

PowerShell uses cmdlets —special commands that allow you to manage the system and automate tasks. The basic naming principle for commands is the verb -entity (e.g., Get-Process , Start -Service ).

1. Basic commands for working with PowerShell

1.1 Getting a list of all available commands

Get-Command

This command shows all available cmdlets , including built-in and installed modules.

1.2. Getting help on a command

Get-Help Get-Process

Used to get a description of a cmdlet , its parameters, and examples. To download the full documentation, run:

Update-Help

1.3. Getting help with examples

Get-Help Get-Service -Examples

18 of 25

POWERSHELL

2. Working with processes

2.1. Getting a list of running processes

Get-Process

2.2. Terminating a process (e.g. Notepad )

Stop-Process -Name notepad –Force

2.3. Sorting processes by processor load

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

3. Working with services

3.1. Getting a list of all services

Get-Service

3.2. Getting the status of a specific service (e.g. Print Spooler )

Get-Service -Name Spooler

3.3. Stopping the service

Stop-Service -Name Spooler –Force

3.4. Launching the service

Start-Service -Name Spooler

4. Examples of basic scripts

4.1. Script for monitoring processes (display processes consuming more than 50% CPU)

Get-Process | Where-Object { $_.CPU - gt 50 } | Select-Object ProcessName , CPU

4.2. Automatically delete files older than 30 days (PowerShell Copy Edit)

$Path = "C:\Logs"

Get- ChildItem $Path -Recurse | Where-Object { $_. LastWriteTime - lt (Get-Date). AddDays (-30) } | Remove-Item –Force

4.3. Creating a backup copy of powershell filesCopyEdit

$Date = Get-Date -Format " yyyy -MM-dd"

$Source = "C:\Data"

$Backup = "D:\Backup\$Date"

New-Item -ItemType Directory -Path $Backup

Copy-Item -Path "$Source\*" -Destination $Backup -Recurse

19 of 25

COMPARISON OF CMD AND POWERSHELL

PowerShell is a more powerful and functional shell than the classic CMD command line . The main differences are listed in the table:

Criterion

CMD (Command Prompt)

PowerShell

Based on

Text processing

Object Model (.NET)

Data type

Only lines

Objects with methods and properties

Teams

Simple commands (dir, copy)

Cmdlets (Get-Process, Get-Service)

Scripts

Batch files (.bat, .cmd)

PowerShell scripts (.ps1)

Automation

Limited

Full-fledged scripts with loops and logic

Access to the system

Basic Windows commands

Access to Windows APIs, WMI, .NET

Working with remote systems

No built-in support

PowerShell Remoting (WS-Man, SSH)

Working with files

Simple (copy, del)

Flexible (Copy-Item, Remove-Item)

Working with processes

tasklist, taskkill

Get-Process, Stop-Process

Working with services

Cannot be controlled directly

Get-Service, Start-Service, Stop-Service

Editing the registry

Impossible

Get-Item, Set-Item for working with the registry

Interactivity

Limited

A full-fledged object-oriented shell

Module support

Absent

Yes (Import-Module, Find-Module)

Interoperability with JSON/XML

Impossible

Built-in parsers (ConvertTo-Json, ConvertFrom-Json)

Used for

Simple commands and diagnostics

Administration, automation, DevOps

20 of 25

PART 1: WORKING WITH THE COMMAND PROMPT (CMD)

Task 1: Basic file system commands

  1. Open Command Prompt (cmd.exe).
  2. Go to the C:\Users\Public directory using the command:

cd C:\Users\Public

3. Create a new folder named TestFolder :

mkdir TestFolder

4. Go to the created folder:

cd TestFolder

5. Create an empty file test.txt:

echo > test.txt

6. Copy the file to the C:\Temp directory (create it if it doesn’t exist)

copy test.txt C:\Temp\

7. Delete the test.txt file:

del test.txt

8. Delete the TestFolder folder :

cd ..

rmdir TestFolder

21 of 25

PART 1: WORKING WITH THE COMMAND PROMPT (CMD)

Task 2: Working with processes and network commands

1. List running processes:

tasklist

2. Terminate the notepad.exe process (if it is running):

taskkill /IM notepad.exe /F

3. Check your connection to the Google website:

ping google.com

4. View the current network configuration:

ipconfig /all

22 of 25

PART 2: WORKING WITH POWERSHELL

Task 3: Basic PowerShell Commands

  1. Open PowerShell and run the following command to see a list of cmdlets :

Get-Command

2. View help for the Get-Process command:

Get-Help Get-Process

3. Get a list of running processes:

Get-Process

4. Stop the notepad.exe process (if running):

Stop-Process -Name notepad –Force

5. List all services:

Get-Service

23 of 25

PART 2: WORKING WITH POWERSHELL

Task 4: Working with Files in PowerShell

1. Create a new folder C:\PS_Test:

New-Item -ItemType Directory -Path C:\PS_Test

2. Create a text file file1.txt in this folder:

New-Item -ItemType File -Path C:\PS_Test\file1.txt

3. Write the line "This is a test file" into the file:

Set-Content C:\PS_Test\file1.txt " This is a test file."

4. Read the contents of the file:

Get-Content C:\PS_Test\file1.txt

5. Copy the file to the C:\Backup folder (create it if necessary):

Copy-Item C:\PS_Test\file1.txt -Destination C:\Backup

6. Delete the original file:

Remove-Item C:\PS_Test\file1.txt

24 of 25

PART 2: WORKING WITH POWERSHELL

Task 5: Automate tasks with PowerShell

1. List all files in C:\Windows, sorted by size:

Get -ChildItem C:\Windows-Recurse | Sort-Object Length -Descending | Select-Object -First 10

2. Get a list of processes consuming more than 100 MB of memory:

Get-Process | Where-Object { $_. WorkingSet - gt 100MB }

3. Delete all files from the C:\Temp folder that were created more than 7 days ago:

Get- ChildItem C:\Temp -Recurse | Where-Object { $_. LastWriteTime - lt (Get-Date). AddDays (-7) } | Remove-Item -Force

4. Create and run a PowerShell script that outputs the text " Hello, PowerShell!" to the file C:\PS_Test\log.txt:

"Hello, PowerShell!" | Out-File C:\PS_Test\log.txt

25 of 25

THANK YOU FOR YOUR ATTENTION