SlideShare a Scribd company logo
PowerShell 101 
Thomas Lee - MCT 
Plataan
Course Overview 
1. What IS PowerShell? 
2. What are Cmdlets, Objects and The Pipeline? 
3. Introducing the PowerShell Language 
4. Installing and using PowerShell 
5. Configuring your environment with profiles 
PowerShell 101
1. What is PowerShell? 
2. PowerShell Architecture 
3. Core PowerShell Components 
1. What is 
PowerShell? 
PowerShell 101
• Microsoft’s Strategic Task Automation Platform for IT 
Professionals 
• Shell – think Unix like 
• Scripting Language – power of Perl/Ruby 
• Extensible – bring on the community 
• Built on .NET and Windows – MS-centric 
1. What is 
PowerShell? 
1.1 What Is PowerShell? 
PowerShell 101
1. What is 
PowerShell? 
1.1 PowerShell Architecture 
PowerShell 101
1. What is 
PowerShell? 
1.1 PowerShell Architecture With Remoting 
PowerShell 101
1. What is 
PowerShell? 
1.2 PowerShell Components 
Cmdlets Objects Pipeline 
PowerShell 101
1. What are Cmdlets? 
2. What are Objects? 
3. What is the Pipeline 
4. Discovery and The Community 
5. Why Does this Design Matter? 
2. Cmdlets, 
Objects, and 
the Pipeline 
PowerShell 101
• A unit of functionality – a mini-program that does something useful 
• Implemented as a .NET Class 
• Get some with PowerShell or with applications and Windows 
roles/feature, buy some commercial Cmdlets, find some on the 
internet, or build your own! 
• Cmdlets can have aliases 
• Built in or add your own 
• Aliases do NOT include parameter aliasing  
• Cmdlets take parameters 
• Parameters have names (prefaced with “-”) 
• Parameter names can be abbreviated and sometimes omitted 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.1 What Are Cmdlets? 
PowerShell 101
• Cmdlets are named with Verb-Noun syntax 
Noun always singular 
Sometimes Verb-PrefixNoun 
• Examples 
Get-Process 
Get-AdUser 
• Discovering cmdlet names and usage is easy 
Get-Help 
Get-Command 
• You can use Get-Verb to get all the verbs 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.1 Cmdlet Naming 
PowerShell 101
• Basic form 
CmdetName -Parametername ParameterValue … 
Get-Process –Name notepad 
• Parameters can be abbreviated or omitted 
Get-Process –Na notepad 
Get-Process notepad 
• Parameter values can include Wildcards (aka ‘globbing’) 
Get-Process –Name power* 
• See help text for details of parameters 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.1 Calling Cmdlets 
PowerShell 101
• A computer abstraction of a real life thing 
A process 
A server 
An AD User 
• Objects have occurrences you manage 
The processes running on a computer 
The users in an OU 
The files in a folder 
• Objects dramatically simplifies scripting 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.2 What are Objects? 
PowerShell 101
• Everything in PowerShell is an object 
• Cmdlets produce and consume objects 
Eg Get-Process produces System.Diagnostics.Process 
• You can use Get-Member to tell you the object type 
• Refer to MSDN for more detail (in most cases!) 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.2 Objects in PowerShell 
PowerShell 101
• PowerShell supports: 
.NET objects 
COM objects 
WMI objects 
Custom Objects 
• Syntax and usage vary 
So similar, yet so different 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.2 PowerShell Object Support 
PowerShell 101
• The pipeline connects cmdlets 
One cmdlet outputs objects 
Next cmdlet uses those objects as input 
Get-Process | Sort-Object Name 
• Pipeline is not a new concept 
Came From Unix/Linux 
PowerShell Pipes objects not text 
• The Pipeline provides rich functionality and convenience 
But there can be a performance hit 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.3 The Pipeline 
PowerShell 101
• Discovery means using the product to find out more about the 
product 
How easy is it to discover what you need to know? 
Discovery is a key attribute of PowerShell 
• Discovery includes 
• Predictable command names (standard verbs, and nouns) 
• Consistent parameter usage 
• Consistent output (objects vs text) 
• Built-in help (Get-Help, Get-Command) 
• Online help (Get-Help Get-Process –Online) 
• Discovery leverages what you know 
• Discovery is something all PowerShell users depend on! 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.4 Discovery And The Community 
PowerShell 101
• You never walk alone 
• HUGE PowerShell ecosystem 
Other PowerShell Users 
Product team 
Vendors 
MVPs 
• Various ways to engage with the community 
• SpiceWorks 
• Twitter 
• PowerShell.Com 
• Microsoft Forums 
• Etc, etc, etc 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.4 The PowerShell Community 
PowerShell 101
• Simple to use 
Far easier to compose 
• Powerful in operation 
PowerShell (and .NET) do the heavy lifting 
• Helps to integrates functionality stacks 
Operating System 
Application (Microsoft and others) 
PowerShell Base 
Community efforts 
• The IT Industry is embracing PowerShell 
Cisco, Vmware, EMC, etc all support PowerShell cmdlets 
2. Cmdlets, 
Objects, and 
the Pipeline 
2.5 Why Does This Design Matter? 
PowerShell 101
• PowerShell is an IT Professional tool to help you manage Windows 
and some non-windows systems 
• PowerShell’s key components include Cmdlets, Objects, and The 
Pipeline 
• This approach has become mainstream both within Microsoft and 
with the wider IT eco-system 
2. Cmdlets, 
Objects, and 
the Pipeline 
Module Summary 
PowerShell 101
1. Introducing the PowerShell Language 
2. Variables and Operators 
3. Scalars (numbers and strings) 
4. Arrays 
5. Hash tables 
6. Variable types 
7. Other language features 
3. The 
PowerShell 
Language 
PowerShell 101
• The PowerShell language is derivative – some parts coming from: 
• Linux and Unix shells 
• Windows CMD.EXE based applications 
• C# 
• DEC DCL 
• Perl 
• And others! 
• You need to know the language before you can write scripts 
• Learning is underpinned by Discovery 
3. The 
PowerShell 
Language 
3.1 Introducing the PowerShell Language 
PowerShell 101
• Variables contain objects during a session 
• Variables named starting with ‘$’ 
$myvariable = 42 
• Variable’s Type is implied (or explicit) 
$myfoo = ls c:foo 
• Variables can put objects into pipeline 
$myfoo | Format-Table name 
• Variables can be reflected on 
$myfoo | Get-Member 
3. The 
PowerShell 
Language 
3.2 Variables 
PowerShell 101
• Some variables come with PowerShell 
$PSVersionTable 
$PSHome 
• Some variables tell PowerShell what to do 
$WarningPreference 
$MaximumHistoryCount 
• You can create variables in Profile(s) that persist 
• See variables by: 
Get-ChildItem Variable:* 
3. The 
PowerShell 
Language 
3.2 Built-in Variables 
PowerShell 101
• Scalar variable contains a single value 
$i=42 
• Can use value directly 
$i=42; $i 
• Often used to calculate a value used for output 
$count = (Get-ChildItem –File C:Foo).count 
"You have {0:n0} files in C:Foo" –f $count 
3. The 
PowerShell 
Language 
3.3 Scalars 
PowerShell 101
• Numbers can be integer or [int] 
• Numbers can be floating point/decimal [double] 
• PowerShell can convert between number and string 
$i = 10 + '10' 
$i #what is $I 
• But sometimes the conversion is not obvious 
• $i = '123' + 10 
• $i #what is $I now 
3. The 
PowerShell 
Language 
3.3 Numbers and Number Conversion 
PowerShell 101
• You can express strings with single quotes ' or double quotes " 
$string1 = 'have a nice day' 
$string2 = "have a nice day" 
• Double quoted strings supports substitution 
$i = 42 
"the value of is $i" 
• Scalar only gotcha 
$s = ls c:foo -file 
"There are $s.count files in c:foo" 
3. The 
PowerShell 
Language 
3.3 Strings 
PowerShell 101
• Array variables contain multiple values 
• Array members addressed with [], e.g. $a[0] 
$a[0] is first 
$a[-1] is last 
Use .GetType() to get type of an array 
$myfoo = LS c:foo 
$myfoo.gettype() 
3. The 
PowerShell 
Language 
3.4 Arrays 
PowerShell 101
• Arrays can be one type, multiple types 
$array = 1, 
'hello',[system.guid]::newguid() 
$array | Get-Member 
• You typically use loop constructs to process an array 
3. The 
PowerShell 
Language 
3.4 More on Arrays 
PowerShell 101
• Special type of an array 
Also known as dictionary or property bag 
• Contains a set of key/value pairs 
Values can be read automagically 
$ht=@{"singer"="Jerry Garcia“; 
"band"="Greatful Dead”} 
$ht.singer 
• Value can be another hash table! 
• Hash tables are used throughout PowerShell 
• For more details see Get-Help about_hash_tables 
3. The 
PowerShell 
Language 
3.5 Hash Tables 
PowerShell 101
• Variables can be implicitly typed 
PowerShell works it out by default 
$I=42;$i.gettype() 
• Variables can be explicitly typed 
[system.int64] $i = 42; $i.gettype() 
• Typing an expression 
$i = [int64] (55 – 13); $i.gettype() 
$i = [int64] 55 – [int32] 13; 
$i.gettype() 
$i = [int32] 55 – [int64] 13; 
$i.gettype() 
3. The 
PowerShell 
Language 
3.6 Variable Type 
PowerShell 101
• To specify type use [<type name>] before variable name 
[System.Int64] $i = 42 
• Type accelerators 
Synthetic types created by PowerShell 
Exist for .NET and WMI objects 
WMI covered more in module 8 
Translated transparently 
[int] translated into [system.int32] 
• Usie type accelerators as if they were real .NET types 
[int64] $i = 42 
3. The 
PowerShell 
Language 
3.6 Types and Type Accellerators 
PowerShell 101
[int]/[int16]/[int32]/[int64] 
[uint]/[uint16]/[uint32]/[uint65] 
[float]/[single]/[double] 
[char]/[byte]/[sbyte] 
[boolean] 
[datetime] 
[guid] 
[void] 
Etc, etc, etc./ 
• NB Some of these are type accelerators 
• You can create new ones – but why? 
3. The 
PowerShell 
Language 
3.6 What Types Can I Use 
PowerShell 101
• Operators 
• Expressions 
• Wild Cards 
• Regular Expressions 
• Case sensitivity – or not 
• You have to know the language to write scripts 
• More details of the scripting language are in separate course(s) 
3. The 
PowerShell 
Language 
3.7 More PowerShell Language Features 
PowerShell 101
• We looked at the PowerShell Language in overview and saw 
Introducing the PowerShell Language 
Variables and Operators 
Scalars (numbers and strings) 
Arrays 
Hash tables 
Variable types 
Other language features 
• There is more to the PowerShell language – but outside the scope of 
this course 
3. The 
PowerShell 
Language 
Module Summary 
PowerShell 101
1. Installing PowerShell 
2. Using PowerShell 
4. Installing 
and using 
PowerShell 
PowerShell 101
• Installation is a bit of a variable feast 
• Installation depends on the OS 
• PowerShell is built into Win 8, Server 2012 R2 and later 
• So nothing to install for these OSs 
• Earlier versions vary 
Different versions of PowerShell are supported on different 
versions of Windows 
With Server 2008 for example, PowerShell was an optional feature 
RTFM Carefully 
• Version 5 is available either as part of Win 10 pre-release or as a 
separate download for Windows 8.x/Server 2012 R2 
• Beware of search engine links to beta versions 
4. Installing 
and using 
PowerShell 
4.1 Installing PowerShell 
PowerShell 101
• From the Windows client/server Start screen 
Windows Server has a PowerShell icon on the start bar 
Or type PowerShell from the Start Screen 
• From the Windows Desktop 
Create an icon on the desktop or start screen if using Windows 8.x 
or later as an alternative to having it on the Start bar 
• PowerShell can also be p-art of an application 
GUI layered on PowerShell (eg Exchange Management Console) 
An application that makes use of PowerShell (eg Server Mangager 
in Server 2012 R2) 
• Third Party IDEs 
PowerShell Plus 
Sapien PowerShell Studio 
PowerGUI 
4. Installing 
and using 
PowerShell 
4.2 Using PowerShell 
PowerShell 101
• Using PowerShell can be as simple as using the application 
• Using Server Manager to install a new feature on windows 
• Using Exchange Management Shell to creat a new mailbox 
• But for most IT Pros using PowerShell means writing scripts that 
automate your IT environment 
• That means writing scripts that utilise objects relevant to your 
needs (files, computers, AD components etc.) 
• More about those aspects of PowerShell in a more detailed 
PowerShell course 
4. Installing 
and using 
PowerShell 
4.2 Using PowerShell 
PowerShell 101
• Installing PowerShell is, increasingly, something you do not need 
to do as it’s already installed 
• You can use PowerShell in a variety of ways 
• From the command line or the ISE (Interactive Scripting 
Environment) 
• From within third party tools (eg PowerGUI) 
• From withing an application that makes use of PowerShell 
under the covers (e.g. Server Manager in Server 2012 R2 and 
later). 
4. Installing 
and using 
PowerShell 
Module Summary 
PowerShell 101
1. What is a profile? 
2. Why do you use Profiles? 
3. What can you put into your profile? 
5. Configuring 
PowerShell 
With Profiles 
PowerShell 101
• Special scripts that run at startup 
• Each System has 4 Profiles 
• Per User for a single PowerShell host (e.g. the ISE) 
• For ALL users for a single PowerShell host 
• Per user for all PowerShell hosts 
• For all users for all PowerShell hosts 
• Profiles allow you to leverage other people’s work and to change 
PowerShell to work like you want 
5. Configuring 
PowerShell 
with Profiles 
5.1 What is a profile? 
PowerShell 101
• You have 4 as follows: 
$profile | Get-Member *Host* | 
Format-List name,definition 
• Most users just use CurrentuserCurrentHost 
$Profile variable points to that file 
5. Configuring 
PowerShell 
with Profiles 
5.1 Where do Profiles Live? 
PowerShell 101
• Profiles are just .ps1 files that run when PowerShell/ISE start 
• You can use the ISE or Notepad to edit them 
• You do not need to use ALL 4 profile – just use $profile inside the 
host 
5. Configuring 
PowerShell 
with Profiles 
5.1 Managing your Profiles 
PowerShell 101
• CurrentUserThisHost profile easiest to manage 
• Built in $profile variable points directly to that file 
• Does it exist? 
Test-Path $profile 
• Create it if not 
New-item –path $profile –itemtype file -Force 
• Edit it in notepad/ISE 
Notepad $profile 
PSEDIT $profile # in ISE only! 
Other Profiles 
Create variable in profile to point to them 
Edit vs. copy 
5. Configuring 
PowerShell 
with Profiles 
5.1 What is a profile? 
PowerShell 101
• Profiles configure your environment as you need it 
• Profiles help to make PowerShell easier for YOU to use 
• You can share profiles to simplify things 
For example AllUsersAllShell profile holds corporate aliases 
• Be careful to avoid your profile files being overly long 
5. Configuring 
PowerShell 
with Profiles 
5.2 Why do you use Profiles? 
PowerShell 101
• Lots of things including: 
Create new variables holding useful things 
Create new Provider drives giving you shortcuts to common places 
including in the registry, the file system, AD, etc 
Setting up your PowerShell Prompt 
Adding menus to the ISE 
Adding functions (or script cmdlets) that you commonly use 
5. Configuring 
PowerShell 
with Profiles 
5.3 What Can You Put Into a Profile? 
PowerShell 101
• Installing PowerShell is, increasingly, something you do not need 
to do as it’s already installed 
• You can use PowerShell in a variety of ways 
• From the command line or the ISE (Interactive Scripting 
Environment) 
• From within third party tools (eg PowerGUI) 
• From within an application that makes use of PowerShell 
under the covers (e.g. Server Manager in Server 2012 R2 and 
later). 
5. 
Configuring 
PowerShell 
with Profiles 
Module Summary 
PowerShell 101
Course Summary 
• In this course we looked at: 
What IS PowerShell? 
What are Cmdlets, Objects and the Pipeline? 
An brief overview to the PowerShell Language 
How you install and use PowerShell 
Configuring PowerShell with profile files 
PowerShell 101
Thank You For Watching 
Plataan 
online & classroom training: www.plataan.be 
www.facebook.com/PlataanAlumni 
@PlataanAlumni 
http://www.linkedin.com/company/plataan 
Plataan App for Windows Phone and iPhone

More Related Content

What's hot

Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
Ahmed El-Arabawy
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and Permissions
Ahmed El-Arabawy
 
Basic commands of linux
Basic commands of linuxBasic commands of linux
Basic commands of linux
shravan saini
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
Ahmed El-Arabawy
 
1 introduction to windows server 2016
1  introduction to windows server 20161  introduction to windows server 2016
1 introduction to windows server 2016
Hameda Hurmat
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
Aditya Konarde
 
Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...
Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...
Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...
Simplilearn
 
infrastructure as code
infrastructure as codeinfrastructure as code
infrastructure as code
Amazon Web Services
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
Harish1983
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
VIKAS TIWARI
 
Docker Networking Deep Dive
Docker Networking Deep DiveDocker Networking Deep Dive
Docker Networking Deep Dive
Docker, Inc.
 
Deploying Azure DevOps using Terraform
Deploying Azure DevOps using TerraformDeploying Azure DevOps using Terraform
Deploying Azure DevOps using Terraform
Adin Ermie
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
Julien Corioland
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
MohanKumar Palanichamy
 
Terraform
TerraformTerraform
Automation with Packer and TerraForm
Automation with Packer and TerraFormAutomation with Packer and TerraForm
Automation with Packer and TerraForm
Wesley Charles Blake
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration Testing
Cheah Eng Soon
 
Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview
Ahmed El-Arabawy
 

What's hot (20)

Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities Course 102: Lecture 7: Simple Utilities
Course 102: Lecture 7: Simple Utilities
 
Course 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and PermissionsCourse 102: Lecture 14: Users and Permissions
Course 102: Lecture 14: Users and Permissions
 
Basic commands of linux
Basic commands of linuxBasic commands of linux
Basic commands of linux
 
Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems Course 102: Lecture 28: Virtual FileSystems
Course 102: Lecture 28: Virtual FileSystems
 
1 introduction to windows server 2016
1  introduction to windows server 20161  introduction to windows server 2016
1 introduction to windows server 2016
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
Linux basics
Linux basicsLinux basics
Linux basics
 
Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...
Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...
Chef Tutorial | Chef Tutorial For Beginners | DevOps Chef Tutorial | DevOps T...
 
infrastructure as code
infrastructure as codeinfrastructure as code
infrastructure as code
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
Docker Networking Deep Dive
Docker Networking Deep DiveDocker Networking Deep Dive
Docker Networking Deep Dive
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Deploying Azure DevOps using Terraform
Deploying Azure DevOps using TerraformDeploying Azure DevOps using Terraform
Deploying Azure DevOps using Terraform
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Terraform
TerraformTerraform
Terraform
 
Automation with Packer and TerraForm
Automation with Packer and TerraFormAutomation with Packer and TerraForm
Automation with Packer and TerraForm
 
Azure Penetration Testing
Azure Penetration TestingAzure Penetration Testing
Azure Penetration Testing
 
Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview Course 102: Lecture 1: Course Overview
Course 102: Lecture 1: Course Overview
 

Similar to PowerShell 101

ITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell Toolmaking
Kurt Roggen [BE]
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
Thomas Lee
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
Nikhil Mittal
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
June Blender
 
Powershell Training
Powershell TrainingPowershell Training
Powershell TrainingFahad Noaman
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
Thomas Lee
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
2014 SpiceWorld London Breakout
2014 SpiceWorld London Breakout2014 SpiceWorld London Breakout
2014 SpiceWorld London Breakout
Thomas Lee
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
Matthew Johnson
 
Python ppt
Python pptPython ppt
Python ppt
Mohita Pandey
 
PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2
Bryan Cafferky
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
Sencha
 
Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data management
Laurent Leturgez
 
.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2
aminmesbahi
 
Taking Advantage of Microsoft PowerShell
Taking Advantage of Microsoft PowerShell Taking Advantage of Microsoft PowerShell
Taking Advantage of Microsoft PowerShell
Global Knowledge Training
 
2016 spice world_london_breakout
2016 spice world_london_breakout2016 spice world_london_breakout
2016 spice world_london_breakout
Thomas Lee
 
Power shell training
Power shell trainingPower shell training
Power shell training
David Brabant
 
Powering up on PowerShell - BSides Greenville 2019
Powering up on PowerShell  - BSides Greenville 2019Powering up on PowerShell  - BSides Greenville 2019
Powering up on PowerShell - BSides Greenville 2019
Fernando Tomlinson, CISSP, MBA
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
Himanshu Sharma
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
ClapperboardCinemaPV
 

Similar to PowerShell 101 (20)

ITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell ToolmakingITPROceed 2016 - The Art of PowerShell Toolmaking
ITPROceed 2016 - The Art of PowerShell Toolmaking
 
PowerShell 101
PowerShell 101PowerShell 101
PowerShell 101
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 
Powershell Training
Powershell TrainingPowershell Training
Powershell Training
 
PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!PowerShell 101 - What is it and Why should YOU Care!
PowerShell 101 - What is it and Why should YOU Care!
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
 
2014 SpiceWorld London Breakout
2014 SpiceWorld London Breakout2014 SpiceWorld London Breakout
2014 SpiceWorld London Breakout
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 
Python ppt
Python pptPython ppt
Python ppt
 
PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2PowerShell Workshop Series: Session 2
PowerShell Workshop Series: Session 2
 
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don GriffinSenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
SenchaCon 2016: Modernizing the Ext JS Class System - Don Griffin
 
Python and Oracle : allies for best of data management
Python and Oracle : allies for best of data managementPython and Oracle : allies for best of data management
Python and Oracle : allies for best of data management
 
.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2.NET Core, ASP.NET Core Course, Session 2
.NET Core, ASP.NET Core Course, Session 2
 
Taking Advantage of Microsoft PowerShell
Taking Advantage of Microsoft PowerShell Taking Advantage of Microsoft PowerShell
Taking Advantage of Microsoft PowerShell
 
2016 spice world_london_breakout
2016 spice world_london_breakout2016 spice world_london_breakout
2016 spice world_london_breakout
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
Powering up on PowerShell - BSides Greenville 2019
Powering up on PowerShell  - BSides Greenville 2019Powering up on PowerShell  - BSides Greenville 2019
Powering up on PowerShell - BSides Greenville 2019
 
C++ Basics
C++ BasicsC++ Basics
C++ Basics
 
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdfLearn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
Learn Powershell Scripting Tutorial Full Course 1dollarcart.com.pdf
 

More from Thomas Lee

Doing Azure With PowerShell
Doing Azure With PowerShellDoing Azure With PowerShell
Doing Azure With PowerShell
Thomas Lee
 
2015 spice world_london_breakout
2015 spice world_london_breakout2015 spice world_london_breakout
2015 spice world_london_breakout
Thomas Lee
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
Thomas Lee
 
Formatting With PowerShell
Formatting With PowerShell Formatting With PowerShell
Formatting With PowerShell
Thomas Lee
 
Top 10 PowerShell Features in Server 2012
Top 10 PowerShell Features in Server 2012Top 10 PowerShell Features in Server 2012
Top 10 PowerShell Features in Server 2012
Thomas Lee
 
Coping with Murphy’s Law
Coping with Murphy’s LawCoping with Murphy’s Law
Coping with Murphy’s Law
Thomas Lee
 
Deep dive formatting
Deep dive formattingDeep dive formatting
Deep dive formattingThomas Lee
 

More from Thomas Lee (7)

Doing Azure With PowerShell
Doing Azure With PowerShellDoing Azure With PowerShell
Doing Azure With PowerShell
 
2015 spice world_london_breakout
2015 spice world_london_breakout2015 spice world_london_breakout
2015 spice world_london_breakout
 
Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!Three cool cmdlets I wish PowerShell Had!
Three cool cmdlets I wish PowerShell Had!
 
Formatting With PowerShell
Formatting With PowerShell Formatting With PowerShell
Formatting With PowerShell
 
Top 10 PowerShell Features in Server 2012
Top 10 PowerShell Features in Server 2012Top 10 PowerShell Features in Server 2012
Top 10 PowerShell Features in Server 2012
 
Coping with Murphy’s Law
Coping with Murphy’s LawCoping with Murphy’s Law
Coping with Murphy’s Law
 
Deep dive formatting
Deep dive formattingDeep dive formatting
Deep dive formatting
 

PowerShell 101

  • 1. PowerShell 101 Thomas Lee - MCT Plataan
  • 2. Course Overview 1. What IS PowerShell? 2. What are Cmdlets, Objects and The Pipeline? 3. Introducing the PowerShell Language 4. Installing and using PowerShell 5. Configuring your environment with profiles PowerShell 101
  • 3. 1. What is PowerShell? 2. PowerShell Architecture 3. Core PowerShell Components 1. What is PowerShell? PowerShell 101
  • 4. • Microsoft’s Strategic Task Automation Platform for IT Professionals • Shell – think Unix like • Scripting Language – power of Perl/Ruby • Extensible – bring on the community • Built on .NET and Windows – MS-centric 1. What is PowerShell? 1.1 What Is PowerShell? PowerShell 101
  • 5. 1. What is PowerShell? 1.1 PowerShell Architecture PowerShell 101
  • 6. 1. What is PowerShell? 1.1 PowerShell Architecture With Remoting PowerShell 101
  • 7. 1. What is PowerShell? 1.2 PowerShell Components Cmdlets Objects Pipeline PowerShell 101
  • 8. 1. What are Cmdlets? 2. What are Objects? 3. What is the Pipeline 4. Discovery and The Community 5. Why Does this Design Matter? 2. Cmdlets, Objects, and the Pipeline PowerShell 101
  • 9. • A unit of functionality – a mini-program that does something useful • Implemented as a .NET Class • Get some with PowerShell or with applications and Windows roles/feature, buy some commercial Cmdlets, find some on the internet, or build your own! • Cmdlets can have aliases • Built in or add your own • Aliases do NOT include parameter aliasing  • Cmdlets take parameters • Parameters have names (prefaced with “-”) • Parameter names can be abbreviated and sometimes omitted 2. Cmdlets, Objects, and the Pipeline 2.1 What Are Cmdlets? PowerShell 101
  • 10. • Cmdlets are named with Verb-Noun syntax Noun always singular Sometimes Verb-PrefixNoun • Examples Get-Process Get-AdUser • Discovering cmdlet names and usage is easy Get-Help Get-Command • You can use Get-Verb to get all the verbs 2. Cmdlets, Objects, and the Pipeline 2.1 Cmdlet Naming PowerShell 101
  • 11. • Basic form CmdetName -Parametername ParameterValue … Get-Process –Name notepad • Parameters can be abbreviated or omitted Get-Process –Na notepad Get-Process notepad • Parameter values can include Wildcards (aka ‘globbing’) Get-Process –Name power* • See help text for details of parameters 2. Cmdlets, Objects, and the Pipeline 2.1 Calling Cmdlets PowerShell 101
  • 12. • A computer abstraction of a real life thing A process A server An AD User • Objects have occurrences you manage The processes running on a computer The users in an OU The files in a folder • Objects dramatically simplifies scripting 2. Cmdlets, Objects, and the Pipeline 2.2 What are Objects? PowerShell 101
  • 13. • Everything in PowerShell is an object • Cmdlets produce and consume objects Eg Get-Process produces System.Diagnostics.Process • You can use Get-Member to tell you the object type • Refer to MSDN for more detail (in most cases!) 2. Cmdlets, Objects, and the Pipeline 2.2 Objects in PowerShell PowerShell 101
  • 14. • PowerShell supports: .NET objects COM objects WMI objects Custom Objects • Syntax and usage vary So similar, yet so different 2. Cmdlets, Objects, and the Pipeline 2.2 PowerShell Object Support PowerShell 101
  • 15. • The pipeline connects cmdlets One cmdlet outputs objects Next cmdlet uses those objects as input Get-Process | Sort-Object Name • Pipeline is not a new concept Came From Unix/Linux PowerShell Pipes objects not text • The Pipeline provides rich functionality and convenience But there can be a performance hit 2. Cmdlets, Objects, and the Pipeline 2.3 The Pipeline PowerShell 101
  • 16. • Discovery means using the product to find out more about the product How easy is it to discover what you need to know? Discovery is a key attribute of PowerShell • Discovery includes • Predictable command names (standard verbs, and nouns) • Consistent parameter usage • Consistent output (objects vs text) • Built-in help (Get-Help, Get-Command) • Online help (Get-Help Get-Process –Online) • Discovery leverages what you know • Discovery is something all PowerShell users depend on! 2. Cmdlets, Objects, and the Pipeline 2.4 Discovery And The Community PowerShell 101
  • 17. • You never walk alone • HUGE PowerShell ecosystem Other PowerShell Users Product team Vendors MVPs • Various ways to engage with the community • SpiceWorks • Twitter • PowerShell.Com • Microsoft Forums • Etc, etc, etc 2. Cmdlets, Objects, and the Pipeline 2.4 The PowerShell Community PowerShell 101
  • 18. • Simple to use Far easier to compose • Powerful in operation PowerShell (and .NET) do the heavy lifting • Helps to integrates functionality stacks Operating System Application (Microsoft and others) PowerShell Base Community efforts • The IT Industry is embracing PowerShell Cisco, Vmware, EMC, etc all support PowerShell cmdlets 2. Cmdlets, Objects, and the Pipeline 2.5 Why Does This Design Matter? PowerShell 101
  • 19. • PowerShell is an IT Professional tool to help you manage Windows and some non-windows systems • PowerShell’s key components include Cmdlets, Objects, and The Pipeline • This approach has become mainstream both within Microsoft and with the wider IT eco-system 2. Cmdlets, Objects, and the Pipeline Module Summary PowerShell 101
  • 20. 1. Introducing the PowerShell Language 2. Variables and Operators 3. Scalars (numbers and strings) 4. Arrays 5. Hash tables 6. Variable types 7. Other language features 3. The PowerShell Language PowerShell 101
  • 21. • The PowerShell language is derivative – some parts coming from: • Linux and Unix shells • Windows CMD.EXE based applications • C# • DEC DCL • Perl • And others! • You need to know the language before you can write scripts • Learning is underpinned by Discovery 3. The PowerShell Language 3.1 Introducing the PowerShell Language PowerShell 101
  • 22. • Variables contain objects during a session • Variables named starting with ‘$’ $myvariable = 42 • Variable’s Type is implied (or explicit) $myfoo = ls c:foo • Variables can put objects into pipeline $myfoo | Format-Table name • Variables can be reflected on $myfoo | Get-Member 3. The PowerShell Language 3.2 Variables PowerShell 101
  • 23. • Some variables come with PowerShell $PSVersionTable $PSHome • Some variables tell PowerShell what to do $WarningPreference $MaximumHistoryCount • You can create variables in Profile(s) that persist • See variables by: Get-ChildItem Variable:* 3. The PowerShell Language 3.2 Built-in Variables PowerShell 101
  • 24. • Scalar variable contains a single value $i=42 • Can use value directly $i=42; $i • Often used to calculate a value used for output $count = (Get-ChildItem –File C:Foo).count "You have {0:n0} files in C:Foo" –f $count 3. The PowerShell Language 3.3 Scalars PowerShell 101
  • 25. • Numbers can be integer or [int] • Numbers can be floating point/decimal [double] • PowerShell can convert between number and string $i = 10 + '10' $i #what is $I • But sometimes the conversion is not obvious • $i = '123' + 10 • $i #what is $I now 3. The PowerShell Language 3.3 Numbers and Number Conversion PowerShell 101
  • 26. • You can express strings with single quotes ' or double quotes " $string1 = 'have a nice day' $string2 = "have a nice day" • Double quoted strings supports substitution $i = 42 "the value of is $i" • Scalar only gotcha $s = ls c:foo -file "There are $s.count files in c:foo" 3. The PowerShell Language 3.3 Strings PowerShell 101
  • 27. • Array variables contain multiple values • Array members addressed with [], e.g. $a[0] $a[0] is first $a[-1] is last Use .GetType() to get type of an array $myfoo = LS c:foo $myfoo.gettype() 3. The PowerShell Language 3.4 Arrays PowerShell 101
  • 28. • Arrays can be one type, multiple types $array = 1, 'hello',[system.guid]::newguid() $array | Get-Member • You typically use loop constructs to process an array 3. The PowerShell Language 3.4 More on Arrays PowerShell 101
  • 29. • Special type of an array Also known as dictionary or property bag • Contains a set of key/value pairs Values can be read automagically $ht=@{"singer"="Jerry Garcia“; "band"="Greatful Dead”} $ht.singer • Value can be another hash table! • Hash tables are used throughout PowerShell • For more details see Get-Help about_hash_tables 3. The PowerShell Language 3.5 Hash Tables PowerShell 101
  • 30. • Variables can be implicitly typed PowerShell works it out by default $I=42;$i.gettype() • Variables can be explicitly typed [system.int64] $i = 42; $i.gettype() • Typing an expression $i = [int64] (55 – 13); $i.gettype() $i = [int64] 55 – [int32] 13; $i.gettype() $i = [int32] 55 – [int64] 13; $i.gettype() 3. The PowerShell Language 3.6 Variable Type PowerShell 101
  • 31. • To specify type use [<type name>] before variable name [System.Int64] $i = 42 • Type accelerators Synthetic types created by PowerShell Exist for .NET and WMI objects WMI covered more in module 8 Translated transparently [int] translated into [system.int32] • Usie type accelerators as if they were real .NET types [int64] $i = 42 3. The PowerShell Language 3.6 Types and Type Accellerators PowerShell 101
  • 32. [int]/[int16]/[int32]/[int64] [uint]/[uint16]/[uint32]/[uint65] [float]/[single]/[double] [char]/[byte]/[sbyte] [boolean] [datetime] [guid] [void] Etc, etc, etc./ • NB Some of these are type accelerators • You can create new ones – but why? 3. The PowerShell Language 3.6 What Types Can I Use PowerShell 101
  • 33. • Operators • Expressions • Wild Cards • Regular Expressions • Case sensitivity – or not • You have to know the language to write scripts • More details of the scripting language are in separate course(s) 3. The PowerShell Language 3.7 More PowerShell Language Features PowerShell 101
  • 34. • We looked at the PowerShell Language in overview and saw Introducing the PowerShell Language Variables and Operators Scalars (numbers and strings) Arrays Hash tables Variable types Other language features • There is more to the PowerShell language – but outside the scope of this course 3. The PowerShell Language Module Summary PowerShell 101
  • 35. 1. Installing PowerShell 2. Using PowerShell 4. Installing and using PowerShell PowerShell 101
  • 36. • Installation is a bit of a variable feast • Installation depends on the OS • PowerShell is built into Win 8, Server 2012 R2 and later • So nothing to install for these OSs • Earlier versions vary Different versions of PowerShell are supported on different versions of Windows With Server 2008 for example, PowerShell was an optional feature RTFM Carefully • Version 5 is available either as part of Win 10 pre-release or as a separate download for Windows 8.x/Server 2012 R2 • Beware of search engine links to beta versions 4. Installing and using PowerShell 4.1 Installing PowerShell PowerShell 101
  • 37. • From the Windows client/server Start screen Windows Server has a PowerShell icon on the start bar Or type PowerShell from the Start Screen • From the Windows Desktop Create an icon on the desktop or start screen if using Windows 8.x or later as an alternative to having it on the Start bar • PowerShell can also be p-art of an application GUI layered on PowerShell (eg Exchange Management Console) An application that makes use of PowerShell (eg Server Mangager in Server 2012 R2) • Third Party IDEs PowerShell Plus Sapien PowerShell Studio PowerGUI 4. Installing and using PowerShell 4.2 Using PowerShell PowerShell 101
  • 38. • Using PowerShell can be as simple as using the application • Using Server Manager to install a new feature on windows • Using Exchange Management Shell to creat a new mailbox • But for most IT Pros using PowerShell means writing scripts that automate your IT environment • That means writing scripts that utilise objects relevant to your needs (files, computers, AD components etc.) • More about those aspects of PowerShell in a more detailed PowerShell course 4. Installing and using PowerShell 4.2 Using PowerShell PowerShell 101
  • 39. • Installing PowerShell is, increasingly, something you do not need to do as it’s already installed • You can use PowerShell in a variety of ways • From the command line or the ISE (Interactive Scripting Environment) • From within third party tools (eg PowerGUI) • From withing an application that makes use of PowerShell under the covers (e.g. Server Manager in Server 2012 R2 and later). 4. Installing and using PowerShell Module Summary PowerShell 101
  • 40. 1. What is a profile? 2. Why do you use Profiles? 3. What can you put into your profile? 5. Configuring PowerShell With Profiles PowerShell 101
  • 41. • Special scripts that run at startup • Each System has 4 Profiles • Per User for a single PowerShell host (e.g. the ISE) • For ALL users for a single PowerShell host • Per user for all PowerShell hosts • For all users for all PowerShell hosts • Profiles allow you to leverage other people’s work and to change PowerShell to work like you want 5. Configuring PowerShell with Profiles 5.1 What is a profile? PowerShell 101
  • 42. • You have 4 as follows: $profile | Get-Member *Host* | Format-List name,definition • Most users just use CurrentuserCurrentHost $Profile variable points to that file 5. Configuring PowerShell with Profiles 5.1 Where do Profiles Live? PowerShell 101
  • 43. • Profiles are just .ps1 files that run when PowerShell/ISE start • You can use the ISE or Notepad to edit them • You do not need to use ALL 4 profile – just use $profile inside the host 5. Configuring PowerShell with Profiles 5.1 Managing your Profiles PowerShell 101
  • 44. • CurrentUserThisHost profile easiest to manage • Built in $profile variable points directly to that file • Does it exist? Test-Path $profile • Create it if not New-item –path $profile –itemtype file -Force • Edit it in notepad/ISE Notepad $profile PSEDIT $profile # in ISE only! Other Profiles Create variable in profile to point to them Edit vs. copy 5. Configuring PowerShell with Profiles 5.1 What is a profile? PowerShell 101
  • 45. • Profiles configure your environment as you need it • Profiles help to make PowerShell easier for YOU to use • You can share profiles to simplify things For example AllUsersAllShell profile holds corporate aliases • Be careful to avoid your profile files being overly long 5. Configuring PowerShell with Profiles 5.2 Why do you use Profiles? PowerShell 101
  • 46. • Lots of things including: Create new variables holding useful things Create new Provider drives giving you shortcuts to common places including in the registry, the file system, AD, etc Setting up your PowerShell Prompt Adding menus to the ISE Adding functions (or script cmdlets) that you commonly use 5. Configuring PowerShell with Profiles 5.3 What Can You Put Into a Profile? PowerShell 101
  • 47. • Installing PowerShell is, increasingly, something you do not need to do as it’s already installed • You can use PowerShell in a variety of ways • From the command line or the ISE (Interactive Scripting Environment) • From within third party tools (eg PowerGUI) • From within an application that makes use of PowerShell under the covers (e.g. Server Manager in Server 2012 R2 and later). 5. Configuring PowerShell with Profiles Module Summary PowerShell 101
  • 48. Course Summary • In this course we looked at: What IS PowerShell? What are Cmdlets, Objects and the Pipeline? An brief overview to the PowerShell Language How you install and use PowerShell Configuring PowerShell with profile files PowerShell 101
  • 49. Thank You For Watching Plataan online & classroom training: www.plataan.be www.facebook.com/PlataanAlumni @PlataanAlumni http://www.linkedin.com/company/plataan Plataan App for Windows Phone and iPhone