Introduction to PowerShell for Office 365 Global Tenant Admins

47
Online Conference June 17 th and 18 th 2015 EVENTS.COLLAB365.COMMUNITY Introduction to PowerShell

Transcript of Introduction to PowerShell for Office 365 Global Tenant Admins

Page 1: Introduction to PowerShell for Office 365 Global Tenant Admins

Online Conference

June 17th and 18th 2015EVENTS.COLLAB365.COMMUNITY

Introduction to PowerShell

Page 2: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Who is Michael

Blumenthal?

[email protected]

Twitter: @MichaelBL

LinkedIn: http://bit.ly/MBB-LI

https://michaelblumenthal.me

TechCommunity.Microsoft.com

Tenant Admin at a leading broadcast media

company

Office 365 MVP

Dev/ITPro Mix

In IT Consulting since 1995

PowerShelling since 2007

Contact

Page 3: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

What is PowerShell?

Page 4: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Why is PowerShell AWESOME?

Write-Host “SO easy to use!”

No Compiling!

Page 5: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

• It’s Easy to Get Started!1

• Learn the PowerShell Syntax2

• Working with O3653

• Best Practices4

PowerShell puts .NET at your fingertips!

Page 6: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Chapter 1

It’s Easy to get Started!

Page 7: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Getting Started with PowerShell

20032008,R22012, R22016

7, 8, 8.1, 10

Page 8: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

The Command Line Window

Page 9: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Windows FeatureWin 8.x

Win 8-10

Page 10: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

The Integrated Script Editor

Page 11: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

PowerShell V3-5 ISE

Page 12: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Intellisense!

Page 13: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Chapter 2

Learn the PowerShell Syntax!

Page 14: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Symbols, Keywords, and Syntax! Oh My!

• Variables1

• Commands2

• Piping3

• Comparisons4

• Flow Control5

• Filtering6

Page 15: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Reading Symbols in Code• (tal Guidance

• Moe, Larry, and }

• The universe started with the Big !

• !Important

• A # of Bacon and # Browns

Page 16: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Variables

• Case Insensitive, Dynamic typing

$something

$true, $false, $null, $profile

$myMessage= “Hello, World”

1

Page 17: Introduction to PowerShell for Office 365 Global Tenant Admins
Page 18: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Commands are called cmdlets.

Verb-Noun

Built-in, Extensible

Get-Help

Get-Member

Get-Command

2

Page 19: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Help!

Page 20: Introduction to PowerShell for Office 365 Global Tenant Admins

Discoverability

Page 21: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Get-Command• Find Cmdlets

• Get details of cmdlets and applications

Page 22: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Aliases

• Dir

• Sort

• Select

• Foreach, also %

Alias cmdlet

• Get-ChildItem

• Sort-object

• Select-object

• Foreach-object

Page 23: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

The Power of Piping!

Output Of Command 1

Input of Command 2

3

Page 24: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Example

Page 25: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Page 26: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Dial zero for an…4

Operator

-eq -le

-ne -like

-gt -notlike

-ge -match

-lt -notmatch

Page 27: Introduction to PowerShell for Office 365 Global Tenant Admins

Example

Page 28: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Taking Control of the Flow• 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

5

Page 29: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Example

Page 30: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Where-Object

•Where {<Test>}Syntax

• V1&2:Dir | Where {$_.Name –like “B*”}

• V3+:Dir | where Name –like B*

Example

6

Page 31: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Executing Scripts

.\filename.ps1

Set-ExecutionPolicyUnrestricted

Page 32: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Chapter 3

Connecting To O365

Page 33: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Get the Cmdlets!Verb-MSOL*AAD

Remote SessionEXO

Verb-PNP*PNP

new-CSOnlineSession; RemoteSK4B

Verb-SPO*SPO

Page 34: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Page 35: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Chapter 4

Best Practices

Page 36: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Use Functions• Function global:Do-Something(){• }

• Function global:Do-Something($someParameter){• }

• Function global:Do-Something{• param ([type]$someParameter=$(“Default Expression”))

• }

Page 37: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Follow the Naming Convention!

•Verb-Noun• 98 Verbs

Page 38: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

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 http:// or https://, the shell will open that URL when the Helpcommand’s –online parameter is used.

• #>

Page 39: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Search for Commands

Refresh the command list

Actions you can take

Page 40: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Self Announcing Functions

Page 41: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Source Code Control

Page 42: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

More Good Ideas

• Always read scripts before running them

Page 43: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

More Good Ideas• Always read scripts before running

them.

• Make yours safe when others don’t

Page 44: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

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

Page 45: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

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

Page 46: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

http://bit.ly/poshresResources

Page 47: Introduction to PowerShell for Office 365 Global Tenant Admins

EVENTS.COLLAB365.COMMUNITY

Script something today!It’s Easy to Get

Started!

PowerShell Syntax

Office 365