Introduction to PowerShell

Slides:



Advertisements
Similar presentations
Rick Toner MCSD, MCPD, MCITP Blog:
Advertisements

Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies
Microsoft PowerShell Tom Roeder CS fa. Motivation.NET as a platform shell web server database access Native access to resources eaiser to manage.
Jason Himmelstein, MVP Senior Technical Director,
James Boother Blog: INTRODUCTION TO POWERSHELL.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
James Boother Blog: AUTOMATING ADMIN TASKS WITH POWERSHELL.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
SJSU CS157B Dr. Lee1  2004 Jenny Mitchell Two Useful Tools You Can’t Live Without by Jenny Mitchell SJSU CS157B Section PHP and MySQL.
MS WINDOWS POWER SHELL CSE 535 Operating Systems.
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
Eric Vogel Software Developer A.J. Boggs & Company.
INTERNET APPLICATION DEVELOPMENT For More visit:
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Microsoft ® Official Course Module XA Using Windows PowerShell ®
SharePoint 2010 Development Environment A Guide to Setup SharePoint 2010 Development Environment on Windows 7 Machine.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
PowerShell for SharePoint Developers and Administrators Michael Blumenthal Magenic Technologies
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
PowerShell For SharePoint Developers Neil Iversen Inetium
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Windows PowerShell. What is Windows PowerShell? A command-line interface (CLI) A new way of developing Windows and other products to be more manageable.
Introduction to SQL Server Automation with Powershell by Chris Sommer.
Ravikanth C.
The full name of PERL is Practical extraction and report language. It is similar to shell script and lot easier & powerful language. Perl is free to download.
Start-SPPowerShell – Introduction to PowerShell for SharePoint Admins and Developers Paul BAker.
Building Powerful Workflow Automation with Cherwell and PowerShell
CS 330 Class 7 Comments on Exam Programming plan for today:
Operating Systems Shell Commands & Script Programming
Achieve more in less time using the new SQL PowerShell
Introduction to Python
To the Command Line and Beyond Jeremy Sublett Composable Systems, LLC
Introduction to PowerShell
CSC 352– Unix Programming, Fall 2012
PHP Introduction.
Getting Started with the Data ONTAP PowerShell Toolkit
SharePoint Saturday Omaha April 2016
Tutorial C#.
Perl for Bioinformatics
PowerShell goodness 2017 Jeremy Sublett Composable Systems, LLC
Web Systems Development (CSC-215)
Control Structures: if Conditional
Control Structures: for & while Loops
PHP.
In this session… Introduce what we’re talking about
PowerShell Best Practices for SQL DBA’s
Cmdlets “Command-lets”
Site scripts and Site Design
IntroductionToPHP Static vs. Dynamic websites
Intro to PHP.
Grow Your Script From Simple to Module
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
CSC 352– Unix Programming, Fall, 2011
PowerShell + SharePoint Online – An Admins Guide to Administration in the O365 Cloud Marrell Sanders – Sr. SharePoint Administrator NACS Branson, MO.
Tech Ed North America /27/ :04 AM Required Slide
PHP an introduction.
The Selection Structure
Introduction to Bash Programming, part 3
Bash Scripting CS 580U - Fall 2018.
INTRODUCTION to PERL PART 1.
SSMS to Azure Data Studio
PowerShell + SharePoint Online – An Admins Guide to Administration in the O365 Cloud Marrell Sanders – Sr. SharePoint Administrator SharePoint Saturday.
PHP By Prof. B.A.Khivsara Note: The material to prepare this presentation has been taken from internet and are generated only for students reference and.
Presentation transcript:

Introduction to PowerShell Michael Blumenthal, MVP

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 Michael@Blumenthalit.com Twitter: @MichaelBL LinkedIn: http://bit.ly/MBB-LI https://michaelblumenthal.me TechCommunity.Microsoft.com

What is PowerShell?

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!

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!

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

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”

The Command Line Window

Windows Feature Win 8-10 Win 8.x

The Integrated Script Editor V2

PowerShell V3-5 ISE

Intellisense! Intellisense!

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

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

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

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 to @variables in SQL, apparently also Ruby, PHP. Arrays start at 0

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

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

Help!

Discoverability Get-Member examples

Get-Command Find Cmdlets Get details of cmdlets and applications

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

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

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

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

Example

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

Example

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

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

Chapter 3 Connecting To O365

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

Demo

Chapter 4 Best Practices

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

Follow the Naming Convention! Verb-Noun 98 Verbs

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 Help command’s –online parameter is used. #>

Search for Commands Refresh the command list Actions you can take

Self Announcing Functions …

Source Code Control

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

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

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

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

Resources http://bit.ly/poshres

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!