Share
Explore

Using PowerShell

Preamble to Running a Simple "Hello, World!" Program with PowerShell
Welcome to PowerShell!
Before we dive into scripting, let's get acquainted with what PowerShell is and why it's a game-changer for system administrators and developers alike.
What is PowerShell?
PowerShell is a task automation and configuration management framework from Microsoft. It consists of a command-line shell and an associated scripting language. But it's not just any shell; it's an object-oriented shell that processes objects rather than plain text, making it incredibly powerful.
Why Learn PowerShell?
Automation: PowerShell lets you automate repetitive tasks, making you more productive and reducing the chance of errors.
Flexibility: It integrates with many platforms, from Windows to Linux to Cloud services.
Powerful Scripting: Beyond simple commands, you can develop complex scripts to manage systems, process data, and more.
Getting Started with PowerShell
Accessing PowerShell:
For Windows users, press Windows + X and select "Windows PowerShell".
For Linux or MacOS users, ensure you have PowerShell Core installed.
The Console:
Once you open PowerShell, you'll see a console window. This is where you'll type commands or scripts and see their output.
Execution Policy:
For security reasons, PowerShell has an execution policy that determines how scripts run. For our learning purposes, we'll set it to RemoteSigned, which means you can run scripts you've created without issues.
To set the execution policy, type Set-ExecutionPolicy RemoteSigned and press Enter.
Your First PowerShell Script: "Hello, World!"
Open Notepad or any text editor:
Start a new file and type Write-Output "Hello, World!".
Save this file on your Desktop as HelloWorld.ps1. The .ps1 extension indicates it's a PowerShell script.
Run the Script:
Return to the PowerShell console.
Navigate to your Desktop by typing cd Desktop and pressing Enter.
Now, to run the script, type ./HelloWorld.ps1 and press Enter.
Voila! You should see the output "Hello, World!" in your console. Congratulations on running your first PowerShell script!
Remember, PowerShell is vast and versatile. Today, you took the first step. With practice, you'll soon master the intricacies of this powerful tool and unlock its full potential. So keep experimenting, keep learning, and most importantly, have fun with it!

Here are five lab exercises for students, segmented into three epochs, to simulate server administration tasks using PowerShell:


Epoch 1: Introduction to PowerShell and Basic Server Administration Tasks
Duration: 2 sessions
1. Basic Command Exploration
Objective: Familiarize students with basic PowerShell commands and syntax.
Use Get-Command to explore available cmdlets.
Retrieve system information using Get-SystemInfo.
List all running processes with Get-Process.
2. File and Directory Management
Objective: Understand how to navigate and manage the file system using PowerShell.
Navigate directories using Set-Location, Push-Location, and Pop-Location.
Create, rename, and delete directories and files using New-Item, Rename-Item, and Remove-Item.
Retrieve file content with Get-Content.
Epoch 2: Advanced Server Administration Tasks
Duration: 3 sessions
3. User Account Management
Objective: Learn to create, modify, and delete user accounts on the server.
Create a new user with New-LocalUser.
Set or change user passwords using Set-LocalUser.
List all users with Get-LocalUser.
Remove a user account with Remove-LocalUser.
4. Service Management
Objective: Understand how to manage server services, ensuring they're running or stopped as needed.
Retrieve the status of all services using Get-Service.
Start, stop, or restart services with Start-Service, Stop-Service, and Restart-Service.
Change the startup type of a service using Set-Service.
Epoch 3: PowerShell Remoting and Scripting
Duration: 4 sessions
5. Remote System Administration Using PowerShell
Objective: Dive deep into PowerShell remoting to manage servers from afar.
Configure your system for PowerShell remoting with Enable-PSRemoting.
Use Enter-PSSession to start an interactive session with a remote server.
Run remote commands with Invoke-Command.
Exit a remote session using Exit-PSSession.
Scripting Challenge: Write a script to gather system information from 5 remote servers and save it to a CSV file. Use Export-CSV to achieve this.
These exercises provide a structured progression from foundational concepts to advanced techniques, ensuring students grasp both the theoretical and practical aspects of server administration with PowerShell. By the end of these exercises, they should be well-prepared for real-world server management tasks.
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.