Eran Kampf
Eran Kampf
3 min read

Short Introduction to Powershell

I have a short introduction to Powershell presentation at SAP today and to make things interesting I made the presentation slides using a Powershell script rather than using Powerpoint (I actually stole and modified this).

So, here are my presentation’s “slides”:

$ppt = {
cls;
write-host Windows PowerShell in 5 minutes;
write-host *******************************;
Read-Host;
write-host * Next-generation command-line shell;
write-host * Object-oriented;
write-host
Read-Host;
cls;
write-host Discoverability;
write-host ***************;
Read-Host;
write-host * Getting started;
Read-Host;
write-host * Demo – Scream for HELP: get-help;
Read-Host;
powershell;
cls;
write-host Commandlets and aliases;
write-host ***********************;
read-host;
write-host * Cmdlet = Verb + Noun;
read-host;
write-host * get-process, get-childitem, clear-host, …?;
read-host;
write-host * Enter aliases;
Read-Host;
write-host * Demo – get-command and get-alias;
Read-Host;
powershell;
cls;
write-host Object-orientation;
write-host ******************;
read-host;
write-host * Developers, developers, developers?;
read-host;
write-host * NO!;
read-host;
write-host * What is an object?;
write-host – Data = properties;
write-host – Operations = methods;
read-host;
write-host * Discoverability: get-member
read-host;
write-host * Demo – Working with system processes – The old way;
write-host;
cmd;
cls;
write-host Object-orientation;
write-host ******************;
write-host;
write-host * Developers, developers, developers?;
write-host;
write-host * NO!;
write-host;
write-host * What is an object?;
write-host – Data = properties;
write-host – Operations = methods;
write-host;
write-host * Discoverability: get-member
write-host * Creation: new-object
write-host;
write-host * Demo – Working with system processes – The old way;
write-host;
write-host * Demo – Working with system processes;
Read-Host;
powershell;
cls;
write-host Drives all the way;
write-host ******************;
read-host;
write-host * What is a drive? [a-Z]:;
read-host;
write-host * Much more;
write-host – HKLM:;
write-host – Cert:;
write-host – Variable:;
write-host – Alias:;
read-host;
write-host * get-psdrive
read-host;
write-host * Demo – Dive into the registry;
Read-Host;
powershell;
cls;
write-host Conclusion;
write-host **********;
read-host;
write-host * 5 commandlets to remember:;
write-host – get-help;
write-host – get-command;
write-host – get-alias;
write-host – get-member;
write-host – get-psdrive;
read-host;
cls;
write-host Q “&” A;
write-host *****;
write-host;
write-host * [email protected];
write-host * https://www.ekampf.com/blog/;
read-host;
$ie = new-object -Com internetexplorer.application;
$ie.Navigate2(“https://www.ekampf.com/blog/”);;)
$ie.visible = 1;
exit;
};
&$ppt;

Below are my presentation notes:

Windows Powershell in 5 minutes
——————————-

Powershell is Microsoft next-generation command-line shell.
It’s important to note that it processes objects and not text and we’ll see how later on…

Discoverability
—————

Get-Help or help syntax – show how to get commands help

Commandlets and aliases
———————–

– Demonstrate Get-Command, Get-Alias (and the other alias functionalities – set, remove)

– Object-Orientation –
Explain the Powershell execution pipeline and the fact that it works on objects and not text.
Get-Member is used to get the object properties and methods.

The old way:
run tasklist.exe
tasklist.exe gives text output and hard to manipulate

The new way:
– Get-Process
– Get-Process | Get-Member
– Get-Process | select name, id
– get-process | where-object {$_.Name -match “^svc*”} | select name, id

Powershell can also work with .NET and COM objects:

New-Object COM sample:
$ie = new-object -comobject InternetExplorer.Application
$ie.navigate2(“www.microsoft.com”)
$ie.visible = $true

New-Object .NET sample: $date = New-Object -Type System.DateTime 1982,02,27
$date.get_DayOfWeek()

Invoke example: $script =
{
$ie = new-object -comobject InternetExplorer.Application
$ie.navigate2(“www.microsoft.com”)
$ie.visible = $true
}
&$script

Drives all the way
——————

Get-PSDrive – return list of available providers
Providers are Powershell’s way to provide access to data

Play with the registry:

cd hklm:\software\Microsoft\
Get-ChildItem
dir
dir | where-object {$_.Name -match “_DeleteMe*” }
New-Item _DeleteMe
dir | where-object {$_.Name -match “_DeleteMe*” }
cd _DeleteMe
New-ItemProperty -Name Test -PropertyType String -Value “bla!”