Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to PowerShell

Similar presentations


Presentation on theme: "Introduction to PowerShell"— Presentation transcript:

1 Introduction to PowerShell
Michael Blumenthal, MVP

2 Who is Michael Blumenthal?
Tenant Admin at a leading broadcast media company Office 365 MVP Dev/ITPro Mix In IT Consulting since 1995 PowerShelling since 2007 Contact LinkedIn: TechCommunity.Microsoft.com

3 What is PowerShell?

4 Why is PowerShell AWESOME?
Write-Host “SO easy to use!” No Compiling! Servers, Desktop OS’s, any .NET API, web services, you name it! No Compliling!

5 PowerShell puts .NET at your fingertips!
It’s Easy to Get Started! 1 Learn the PowerShell Syntax 2 Working with O365 3 Best Practices 4 Who would like another tool in their toolbox? How about the swiss army knife of tools? It will make you a more productive developer!

6 It’s Easy to get Started!
Chapter 1 It’s Easy to get Started!

7 Getting Started with PowerShell
2003 2008,R2 2012, R2 2016 7, 8, 8.1, 10 Who here already has installed and PowerShell? Who’s using Server 2003? 2008? Win 2008 – It’s an OS Feature – “servermanagercmd –install PowerShell”

8 The Command Line Window

9 Windows Feature Win 8-10 Win 8.x

10 The Integrated Script Editor
V2

11 PowerShell V3-5 ISE

12 Intellisense! Intellisense!

13 Learn the PowerShell Syntax!
Chapter 2 Learn the PowerShell Syntax!

14 Symbols, Keywords, and Syntax! Oh My!
Variables 1 Commands 2 Piping 3 Comparisons 4 Flow Control 5 Filtering 6

15 Reading Symbols in Code
(tal Guidance Moe, Larry, and } The universe started with the Big ! !Important A # of Bacon and # Browns

16 1 $something Case Insensitive, Dynamic typing
Variables Case Insensitive, Dynamic typing $something $true, $false, $null, $profile $myMessage= “Hello, World” begin with a $ Name that Language… Similar in SQL, apparently also Ruby, PHP. Arrays start at 0

17 Remove $opposite; add write-host; get-item

18 Commands are called cmdlets.
2 Commands are called cmdlets. Verb-Noun Built-in, Extensible Get-Help Get-Member Get-Command Mention Aliases

19 Help!

20 Discoverability Get-Member examples

21 Get-Command Find Cmdlets Get details of cmdlets and applications

22 Aliases Alias cmdlet Dir Get-ChildItem Sort Sort-object Select
Foreach, also % Get-ChildItem Sort-object Select-object Foreach-object

23 3 The Power of Piping! Output Of Command 1 Input of Command 2 |

24 Example Can you imagine trying to do this if this was just text?

25

26 Dial zero for an… -eq -le -ne -like -gt -notlike -ge -match -lt
4 Dial zero for an… Operator -eq -le -ne -like -gt -notlike -ge -match -lt -notmatch

27 Example

28 Taking Control of the Flow
5 If (Test) {Commands} else {Commands} if ($web.Title –ne “”) {Write-Host $web.Title} If For (Init;Test;Repeat) {Commands} for($i=1; $i -le 10; $i++) {Write-Host $i} For Foreach (Item in Collection) {Commands} Foreach ($gumball in $CandyBag) {$gumball.color} Collection | Foreach {Commands} ForEach While (Condition){Commands} while($val -ne 3){$val++; Write-Host $val} While Get-Help about_flow_control Mention that collections start at 0

29 Example

30 Where {<Test>} Where-Object Syntax Example 6
V1&2: Dir | Where {$_.Name –like “B*”} V3+: Dir | where Name –like B* Example

31 Set-ExecutionPolicy Unrestricted
Executing Scripts .\filename.ps1 Set-ExecutionPolicy Unrestricted

32 Chapter 3 Connecting To O365

33 Get the Cmdlets! AAD EXO PNP SK4B SPO Verb-MSOL* Remote Session
Verb-PNP* PNP new-CSOnlineSession; Remote SK4B Verb-SPO* SPO

34 Demo

35 Chapter 4 Best Practices

36 Use Functions Function global:Do-Something(){ }
Function global:Do-Something($someParameter){ Function global:Do-Something{ param ([type]$someParameter=$(“Default Expression”)) Single purpose vs multitool

37 Follow the Naming Convention!
Verb-Noun 98 Verbs

38 Comment your functions
<# .SYNOPSIS –a brief explanation of what the script or function does. .DESCRIPTION – a more detailed explanation of what the script or function does. .PARAMETER name – an explanation of a specific parameter. Replace name with the parameter name. You can have one of these sections for each parameter the script or function uses. .EXAMPLE – an example of how to use the script or function. You can have multiple .EXAMPLE sections if you want to provide more than one example. .NOTES – any miscellaneous notes on using the script or function. .LINK – a cross-reference to another help topic; you can have more than one of these. If you include a URL beginning with or the shell will open that URL when the Help command’s –online parameter is used. #>

39 Search for Commands Refresh the command list Actions you can take

40 Self Announcing Functions

41 Source Code Control

42 Always read scripts before running them
More Good Ideas Always read scripts before running them Be a tool maker

43 Make yours safe when others don’t
More Good Ideas Always read scripts before running them. Make yours safe when others don’t

44 More Good Ideas Always read scripts before running them
Make yours safe when others don’t Check for valid parameter values get-help about_Functions_Advanced_Parameters

45 More Good Ideas Always read scripts before running them
Make yours safe when others don’t Check for valid parameter values get-help about_Functions_Advanced_Parameters Do error handling get-help about_Try_Catch_Finally get-help about_CommonParameters -ErrorAction and -ErrorVariable

46 Resources

47 Script something today!
It’s Easy to Get Started! PowerShell Syntax Office 365 You owe it to yourself to try out PowerShell. It will make you a better developer!


Download ppt "Introduction to PowerShell"

Similar presentations


Ads by Google