
PowerShell Scripting Tutorial
This is an introductory live training session for PowerShell scripting for beginners.
Downloads:
IT Lab
In this Webinar we are going to cover the following:
- Variables
- User Input
- If Statements
- Switch Statements
- Writing to the console (echo / write-host)
- For Loops
- ForEach Loops
- Progress Bars
- Sleep
- Create Directories
- OGV (Out-GridView
- Importing Spreadsheets (CSV)
- Sub-expression operators
Code listed below:
# PowerShell Examples
# Read user input
$Input = Read-Host -Prompt "Please enter your first name"
Write-Host "Hello $Input, it is nice to meet you!"
# If statement
if(1 -eq 2) {
Write-Host "True"
} else {
Write-Host "False"
}
# Combine user input with read host"
$Input = Read-Host -Prompt "Please enter your first name"
if("$Input" -eq "Paul") {
Write-Host "I know who Paul is!"
} else {
Write-Host "I am sorry... I dont know who $Input is."
}
# Switch statement
$Input = Read-Host -Prompt "Please enter your first name"
switch ($Input) {
"Paul" { write-host "I know who paul is!" }
"Joe" { write-host "I know who Joe is!" }
"Mark" { write-host "I know who Mark is!" }
default { write-host "I am sorry... I dont know who $Input is..." }
}
# For loop
for ($i = 1; $i -le 100; $i++ )
{
Write-Host "$i"
$i++
}
# Progress counter
for ($i = 1; $i -le 100; $i++ )
{
Write-Progress -Activity "Search in Progress" -Status "$i% Complete:" -PercentComplete $i;
sleep -Milliseconds 50
}
# Create folders with prefix
$Prefix = Read-Host -Prompt "Prefix of the folders you want to create"
$Count = Read-Host -Prompt "Prefix of the folders you want to create"
for ($i = 1; $i -le $Count; $i++ )
{
mkdir "$($Prefix)_$($i)"
}
# Read CSV file input
$csv = Import-Csv -Path ""