Skip to content
-
technology GuruGyaan

GuruGyan

technology GuruGyaan

GuruGyan

  • Home
  • Linux
  • Windows
  • Contact Us
  • Home
  • Linux
  • Windows
  • Contact Us
Close

Search

technology GuruGyaan

GuruGyan

technology GuruGyaan

GuruGyan

  • Home
  • Linux
  • Windows
  • Contact Us
  • Home
  • Linux
  • Windows
  • Contact Us
Close

Search

Home/language/PowerShell Tutorial for Beginners: Learn PowerShell Scripting with Practical Examples (2026)
language

PowerShell Tutorial for Beginners: Learn PowerShell Scripting with Practical Examples (2026)

By vkgandhig
July 25, 2026 5 Min Read
0

PowerShell is a powerful command-line shell and scripting language developed by Microsoft for automating system administration, configuration management, and repetitive tasks. It is widely used by Windows administrators, DevOps engineers, cloud engineers, and IT professionals to manage Windows, Linux, macOS, Azure, Microsoft 365, and other enterprise environments.

This comprehensive guide covers PowerShell fundamentals, practical examples, advanced concepts, best practices, and complete SEO metadata.


What is PowerShell?

PowerShell is a cross-platform command-line shell and scripting language built on the .NET platform. Unlike traditional command-line tools that work with plain text, PowerShell works with objects, making it easier to automate administrative tasks and process data.

PowerShell helps you:

  • Automate repetitive tasks
  • Manage Windows servers
  • Configure Active Directory
  • Manage Azure resources
  • Administer Microsoft 365
  • Create automation scripts
  • Work with files and processes
  • Manage remote computers

History of PowerShell

  • 2006 – Windows PowerShell 1.0 released by Microsoft.
  • 2016 – PowerShell became open source.
  • 2018 – PowerShell Core introduced for Windows, Linux, and macOS.
  • Today – PowerShell 7 is the recommended cross-platform version.

Why Learn PowerShell?

PowerShell is one of the most valuable skills for IT professionals and administrators.

Benefits

  • Powerful automation capabilities
  • Easy system administration
  • Cross-platform support
  • Object-oriented scripting
  • Built into Windows
  • Excellent for cloud management
  • Essential for Microsoft technologies
  • High demand in enterprise environments

Features of PowerShell

  • Object-oriented pipeline
  • Cross-platform support
  • Powerful scripting language
  • Remote management
  • Modules and packages
  • Secure execution policies
  • Access to .NET libraries
  • Rich error handling
  • Task scheduling
  • Integration with Azure and Microsoft 365

Applications of PowerShell

PowerShell is commonly used for:

  • Windows administration
  • Active Directory management
  • Azure automation
  • Microsoft 365 administration
  • Exchange Server management
  • Hyper-V management
  • Backup automation
  • Software deployment
  • DevOps pipelines
  • Server monitoring

Installing PowerShell

Windows

PowerShell is included with Windows. For the latest features, install PowerShell 7 from Microsoft’s official website.

Verify installation:

$PSVersionTable.PSVersion

Linux

Install PowerShell using your distribution’s package manager.

Example (Ubuntu):

sudo apt install powershell

macOS

Install using Homebrew:

brew install powershell

Start PowerShell:

pwsh

Your First PowerShell Script

Create a file named Hello.ps1

Write-Host "Hello, World!"

Run the script

.\Hello.ps1

Output

Hello, World!

Understanding the Script

Write-Host

Displays text directly in the console.


Variables

$name = "Vikash"

Write-Host $name

Output

Vikash

Data Types

$number = 100

$text = "PowerShell"

$price = 99.99

$isAdmin = $true

Common data types include:

  • String
  • Integer
  • Boolean
  • Double
  • Array
  • Hashtable
  • DateTime

Comments

Single-line comment

# This is a comment

Multi-line comment

<#

This is a

multi-line comment

#>

Taking User Input

$name = Read-Host "Enter your name"

Write-Host "Welcome $name"

Arithmetic Operations

$a = 20
$b = 10

Write-Host ($a + $b)
Write-Host ($a - $b)
Write-Host ($a * $b)
Write-Host ($a / $b)
Write-Host ($a % $b)

If Statement

$age = 20

if($age -ge 18){

Write-Host "Adult"

}

If Else

$number = 5

if($number % 2 -eq 0){

Write-Host "Even"

}
else{

Write-Host "Odd"

}

Switch Statement

$day = 2

switch($day){

1 { "Monday" }

2 { "Tuesday" }

3 { "Wednesday" }

Default { "Invalid" }

}

For Loop

for($i=1;$i -le 5;$i++){

Write-Host $i

}

Foreach Loop

$fruits = "Apple","Banana","Orange"

foreach($fruit in $fruits){

Write-Host $fruit

}

While Loop

$count = 1

while($count -le 5){

Write-Host $count

$count++

}

Functions

function Add-Numbers{

param(

[int]$a,

[int]$b

)

$a + $b

}

Add-Numbers 10 20

Output

30

Arrays

$colors = @("Red","Green","Blue")

$colors[0]

$colors[1]

Hashtable

$user = @{

Name = "Rahul"

Age = 25

City = "Delhi"

}

$user["Name"]

Working with Files

Create a file

New-Item test.txt -ItemType File

Copy a file

Copy-Item test.txt backup.txt

Move a file

Move-Item backup.txt Archive\

Delete a file

Remove-Item test.txt

Reading a File

Get-Content data.txt

Writing to a File

"Hello PowerShell" | Out-File output.txt

Append

"New Line" | Add-Content output.txt

Working with Directories

List files

Get-ChildItem

Create directory

New-Item MyFolder -ItemType Directory

Delete directory

Remove-Item MyFolder -Recurse

Processes

View running processes

Get-Process

Stop a process

Stop-Process -Name notepad

Services

View services

Get-Service

Start service

Start-Service Spooler

Stop service

Stop-Service Spooler

Restart service

Restart-Service Spooler

Remote Management

Run a command on a remote computer

Invoke-Command -ComputerName Server01 -ScriptBlock {

Get-Process

}

Installing Modules

Install-Module Az

Import module

Import-Module Az

Error Handling

try{

Get-Content file.txt

}
catch{

Write-Host "File not found."

}
finally{

Write-Host "Finished."

}

Scheduled Tasks

Run a script automatically using Windows Task Scheduler.

Example command

powershell.exe -File "C:\Scripts\Backup.ps1"

PowerShell Pipeline

Get-Process |

Where-Object {

$_.CPU -gt 100

}

The pipeline passes objects between commands, making data processing efficient and readable.


Common PowerShell Cmdlets

CmdletDescription
Get-HelpDisplay help information
Get-CommandList available commands
Get-ProcessDisplay running processes
Get-ServiceDisplay services
Get-ChildItemList files and folders
Copy-ItemCopy files
Move-ItemMove files
Remove-ItemDelete files
Get-ContentRead file contents
Set-ContentWrite file contents
Test-PathCheck if a path exists
Invoke-WebRequestRetrieve web content
Start-ProcessStart a process
Stop-ProcessStop a process

PowerShell Best Practices

  • Use approved verb-noun naming for functions (for example, Get-User).
  • Add comments and documentation.
  • Use try, catch, and finally for error handling.
  • Validate user input.
  • Avoid hard-coded values.
  • Reuse code with functions and modules.
  • Follow consistent formatting.
  • Test scripts in a non-production environment.
  • Sign scripts where appropriate.
  • Keep PowerShell updated.

Advantages of PowerShell

  • Powerful automation
  • Object-oriented pipeline
  • Cross-platform support
  • Rich .NET integration
  • Excellent Windows management
  • Large module ecosystem
  • Remote administration capabilities
  • Ideal for enterprise automation

Limitations of PowerShell

  • Steeper learning curve than basic command shells.
  • Some modules are Windows-specific.
  • Execution policies can prevent scripts from running until configured.
  • Cross-platform compatibility varies for certain Windows-focused cmdlets.

Career Opportunities

PowerShell skills are valuable for roles such as:

  • Windows System Administrator
  • DevOps Engineer
  • Cloud Engineer
  • Azure Administrator
  • IT Support Engineer
  • Infrastructure Engineer
  • Automation Engineer
  • Cybersecurity Analyst

Frequently Asked Questions (FAQs)

What is PowerShell?

PowerShell is a command-line shell and scripting language developed by Microsoft for system administration and automation.


Is PowerShell only for Windows?

No. Modern PowerShell (PowerShell 7) runs on Windows, Linux, and macOS.


Is PowerShell a programming language?

PowerShell is primarily a scripting language designed for automation, administration, and configuration management.


What is the difference between CMD and PowerShell?

CMD works mainly with text-based commands, while PowerShell works with structured .NET objects, offering more powerful automation and scripting capabilities.


Should beginners learn PowerShell?

Yes. If you work with Windows administration, Azure, Microsoft 365, or DevOps, PowerShell is an excellent skill to learn.


Conclusion

PowerShell is one of the most powerful automation tools available for Windows and cross-platform system management. Its object-oriented pipeline, extensive cmdlets, and integration with .NET and Microsoft services make it indispensable for IT professionals. By mastering PowerShell fundamentals—such as variables, loops, functions, pipelines, and remote management—you can automate complex administrative tasks and improve productivity.


External Link Suggestions:

  • Microsoft PowerShell Documentation: https://learn.microsoft.com/powershell/
  • PowerShell Gallery: https://www.powershellgallery.com/
  • Microsoft Learn PowerShell: https://learn.microsoft.com/training/powershell/
  • PowerShell GitHub Repository: https://github.com/PowerShell/PowerShell

Tags:

Azure AutomationCloud AdministrationDevOpsIT AutomationLearn PowerShellMicrosoft PowerShellPowerShellPowerShell 7PowerShell AutomationPowerShell CmdletsPowerShell CommandsPowerShell ExamplesPowerShell PipelinePowerShell ScriptingPowerShell TutorialScripting LanguageSystem AdministrationWindows PowerShellWindows Server
Author

vkgandhig

Follow Me
Other Articles
Previous

Bash Scripting Tutorial for Beginners: Learn Bash Shell with Practical Examples (2026)

Next

OpenAI Codex: The Complete Guide to AI-Powered Coding in 2026

No Comment! Be the first one.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright 2026 — GuruGyaan. All rights reserved. Privacy Policy