in just one hour i will make you a power shell ninja
DESCRIPTION
A one-hour blast through the basics of PowerShell with particular focus on discovery within the environments, and with a demo at the end of a PowerShell take on Wordpress's Hello Dolly pluginTRANSCRIPT
In Just One Hour I Will Make You A PowerShell
Ninja
A Flying Start Into PowerShell
What you should haveIn your meeting invite, you should have received a list of pre-reqs
● Laptop running Windows 7 or later (not RT)● A text file containing, line-by-line, the lyrics to your favourite
song ● Your typing fingers● Optional: exposure to other programming languages such as C,
C#, Java, Perl, Python, JavaScript or VBScript● Distractions are strictly banned. Close all non-powershell
windows and put your phone face down on the table.
What we will doA crash course into Powershell Basics, including:
● The Raw Language Basics - covered more fully in a later module
● The Help System and exploring the environment● The Pipeline● Working with files and folders● A quick peek at Profiles - covered more fully in a later module
It’s a lot to cover in an hour, and we’re bound to get sidetracked, so let’s get started
Getting StartedThis is a hands-on lab. Fire Up PowerShellThe icon looks like this:
Getting started with CmdletsCmdlets are what they sound like. They’re little commandsThey do stuff, usually fairly simple stuffThey Get- stuff. They Set- stuff. They Invoke- stuff. They Test- stuffThey’re the tiny engines of powershellMany of them have quick, snappy aliases
A thing called the pipelinethe pipeline allows you to string commands together, shunting data from left to right
OK, Yeah, but it’s better than thatConsider the following code snippet
The basics summarised● Variables are prefixed with a dollar sign● Code blocks are delimited with curly braces● Assignment operators are =, +, etc● Comparison Operators are -lt, -gt, -eq, -like etc● Commands (called Cmdlets in PS World) follow a
Verb-Noun convention● Powershell is extensible via Modules● But you REALLY don’t need to remember thisBecause….
Powershell is internally-documentedThere are Cmdlets that tell you about Cmdlets
● Get-Command● Get-Help● Get-Alias● Get-Module● Get-Member
Environment VariablesYou’ll also want to know about environment variables
$Env:$home$psversiontable
OK, so what next?So far you’ve just been working at the prompt
Now it’s time to start writing basic scripts.
First, let’s get set up
Simple functions Functions allow you to package up lumps of code and call them from other lumps of code.We’re going to write a function now.Then we’re going to modify itThen we’re going to run itThen (bonus!) we’re going to make it run whenever we start powershell
In summaryYou now have the tools you need to:● Run commands● Write scripts● Find help● Customise your environmentSo go forth and be a ninja