POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and...

51
Best Practices, Remote Management, Automation and More POWERSHELL

Transcript of POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and...

Page 1: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

Best Practices, Remote Management,

Automation and More

POWERSHELL

Page 2: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

Jason is a 30-year IT veteran and author at Pluralsight. He’s an avid

supporter of the DevOps/PowerShell community as a board member and

CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit.

He is also a Windows PowerShell MVP. Jason focuses on automation and

configuration management for DevOps and has co-authored several

PowerShell, MS Exchange and IIS related discussions on the Microsoft

Virtual Academy.

Best Practices, Remote Management,

Automation and More

POWERSHELL

@theJasonHelmick

[email protected]

Author/Evangelist

Pluralsight

#ILTAG119

Page 3: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

WHY POWERSHELL MATTERS

• Automation has a major impact to your business and its agility

• Automate repetitive tasks

• Deliver reusable solutions

• Reduce failure due to human mistakes

• PowerShell is your gateway to configuration management and

DevOps

#ILTAG119

Page 4: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

WHY DEVOPS MATTERS

• Reduced outages

• Rapid deployment

• Run toward change, not away

• Fail often, recover fast

#ILTAG119

Page 5: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

WHY DEVOPS MATTERS

• High performers decisively outperform lower preforming competition

• Deploy 200 times for frequently

• Recover 24 times faster

• 3 times lower change failure rate

• https://puppet.com/resources/white-paper/2016-state-of-devops-report

#ILTAG119

Page 6: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

GETTING STARTED

Page 7: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• The purpose for PowerShell

• Installing PowerShell – Windows Management Framework

• Launching PowerShell for the administrator

• Customize the shell for comfort

• Getting familiar with the shell

#ILTAG119

Page 8: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

LAUNCHING POWERSHELL FOR THE ADMINISTRATOR

#ILTAG119

Page 9: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

CUSTOMIZE THE SHELL FOR COMFORT

#ILTAG119

Page 10: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

GETTING FAMILIAR WITH THE SHELL

• Cmdlets : Verb – Noun

• Native commands work!

• Examples – Ping, IPConfig, calc, notepad, mspaint

• cls - Clear-Host

• cd - Set-Location

• dir, ls - Get-Childitem

• type, cat - Get-Content

#ILTAG119

Page 11: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

THE HELP SYSTEM

Page 12: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• Why you need help

• Updatable Help

• Discoverability with the Help system

• Understanding Syntax

• Real-World using Help

#ILTAG119

Page 13: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

WHY YOU NEED HELP

• Vast resource at your finger tips to help make you successful

• Don’t memorize – Discover!

• Thousands of cmdlets – all have help!

• Scripting resources and information

• Advanced PowerShell configuration information

#ILTAG119

Page 14: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

UPDATABLE HELP

• Update to the latest version of Help

• Save-Help to save to a local location

#ILTAG119

Page 15: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

DISCOVERABILITY WITH THE HELP SYSTEM

• Get-Help

• Help <cmdlet>

• Help *partial*

• Help <verb/noun>

• Help <cmdlet> -Full

• Help <cmdlet> -ShowCommand

• Get-Help About_*

#ILTAG119

Page 16: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

UNDERSTANDING SYNTAX

• The meaning of Syntax

- Indicates A Parameter

<> Indicates Arguments

[] Argument Accepts Multiple Values

[Param] is Positional [Param Arg] is Optional

#ILTAG119

Page 17: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

REAL-WORLD USING HELP#ILTAG119

Page 18: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

THE PIPELINE: GETTING CONNECTED

Page 19: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• What’s the pipeline and what does it do?

• Exporting/Importing CSV

• Exporting/Importing XML

• Other files and printers

• Displaying information in a GUI

• Making a webpage of information

• Cmdlets that kill

#ILTAG119

Page 20: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

WHAT’S THE PIPELINE AND WHAT DOES IT DO?

Pipe character located above the Enter key

Connects cmdlets to produce better results

Can be broken into several lines to increase readability

#ILTAG119

Page 21: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

EXPORTING/IMPORTING CSV

#ILTAG119

Page 22: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

EXPORTING/IMPORTING XML#ILTAG119

Page 23: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

OTHER FILES AND PRINTERS #ILTAG119

Page 24: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

DISPLAYING INFORMATION IN A GUI#ILTAG119

Page 25: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MAKING A WEBPAGE OF INFORMATION#ILTAG119

Page 26: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

CMDLETS THAT KILL

• Stop-Process / kill

• Stop-service

• $ConfirmPreference

• $WhatIfPreference

• -Confirm

• -Whatif

#ILTAG119

Page 27: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

EXTENDING THE SHELL

Page 28: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• Finding and adding Modules

• Discovering new commands

• The real world of cmdlets

#ILTAG119

Page 29: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

LIKE THE MMC - ONE SHELL DOES IT ALL

#ILTAG119

Page 30: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

FINDING & ADDING MODULES

#ILTAG119

Page 31: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

DISCOVERING NEW COMMANDS

#ILTAG119

Page 32: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

THE POWER IN POWERSHELL -REMOTING

Page 33: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• Overview of Remoting

• Enable Remoting

• One-To-One

• One-To-Many

• Not the end yet!

#ILTAG119

Page 34: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

OVERVIEW OF REMOTING

#ILTAG119

Page 35: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

ENABLE REMOTING

Computer Configuration/Policies/Administrative

Templates/Windows Components/Windows Remote Management

#ILTAG119

Page 36: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

ONE TO ONE - INTERACTIVE

#ILTAG119

Page 37: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

ONE-TO-MANY

#ILTAG119

Page 38: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

AUTOMATION IN SCALE - REMOTING

Page 39: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• Reusable Sessions

• Sessions with Invoke-Command

• Real-world deployment of a website

• Getting commands from anywhere

#ILTAG119

Page 40: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

REUSABLE SESSIONS

#ILTAG119

Page 41: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

SESSIONS WITH INVOKE-COMMAND

#ILTAG119

Page 42: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

GETTING COMMANDS FROM ANYWHERE -

IMPLICIT REMOTING

#ILTAG119

Page 43: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

INTRODUCTION TO TOOLMAKING

Page 44: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MODULE OVERVIEW

• The new ISE

• Making commands repeatable

• Adding parameters to your script

• Documenting your script

• Turning your script into a tool for others

• Storing your tools in a module

#ILTAG119

Page 45: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

MAKING COMMANDS REPEATABLE

#ILTAG119

Page 46: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

ADDING PARAMETERS TO YOUR SCRIPT

#ILTAG119

Page 47: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

DOCUMENTING YOUR SCRIPT

#ILTAG119

Page 48: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

TURNING YOUR SCRIPT INTO A TOOL FOR OTHERS

#ILTAG119

Page 49: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

STORING YOUR TOOLS IN A MODULE

#ILTAG119

Page 50: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows

INTRODUCTION TO POWERSHELL DESIRED STATE CONFIGURATION

Page 51: POWERSHELL · 2017-08-03 · supporter of the DevOps/PowerShell community as a board member and CFO/COO of PowerShell.Org and the PowerShell/DevOps Global Summit. He is also a Windows