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:
- Command Line Interface (CLI): PowerShell provides a command line interface where you can type commands to execute tasks.
- Sessions: A PowerShell session is like a terminal window, where you can interact with the shell, run commands, and access information.
- Cmdlets: Cmdlets are the building blocks of PowerShell. They're lightweight, self-contained modules that perform specific tasks.
Basic Syntax:
- Variables: In PowerShell, variables start with a
$ symbol. For example:
$myVariable = "Hello, World!"
echo $myVariable # outputs "Hello, World!"
- 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!"
- 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:
- Get-Date: Retrieves the current date and time.
powershell
Get-Date # outputs the current date and time
- Write-Host: Outputs text to the console.
powershell
Write-Host "Hello, World!" # outputs "Hello, World!"
- 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!