Selected topic

Introduction to PowerShell

Basics

Prefer practical output? Use related tools below while reading.

What is PowerShell?

PowerShell is a task automation and configuration management framework from Microsoft. It allows you to run commands, scripts, and tools on Windows computers.

Basic Concepts:

  1. Command Line Interface (CLI): PowerShell provides a command line interface where you can type commands to execute tasks.
  2. Sessions: A PowerShell session is like a terminal window, where you can interact with the shell, run commands, and access information.
  3. Cmdlets: Cmdlets are the building blocks of PowerShell. They're lightweight, self-contained modules that perform specific tasks.

Basic Syntax:

  1. Variables: In PowerShell, variables start with a $ symbol. For example:
$myVariable = "Hello, World!"
echo $myVariable  # outputs "Hello, World!"
  1. Functions: Functions are reusable blocks of code that perform specific tasks. Here's an example:
powershell
function Greet {
    param ($name)
    echo "Hello, $name!"
}

Greet -name "John" # outputs "Hello, John!"


  1. Arrays: Arrays in PowerShell are like lists in other languages. They're denoted by the @() syntax:
powershell
$myArray = @("apple", "banana", "orange")
echo $myArray[1] # outputs "banana"

Basic Commands:


  1. Get-Date: Retrieves the current date and time.
powershell
Get-Date # outputs the current date and time

  1. Write-Host: Outputs text to the console.
powershell
Write-Host "Hello, World!" # outputs "Hello, World!"

  1. Get-Process: Lists all running processes on your system.
powershell
Get-Process | Select-Object -Property ProcessName, Id # lists processes with name and ID

These are just some of the basics of PowerShell. I hope this summary helps you get started with using PowerShell!