SharePoint Fest DC 2016_Advanced Office365 SharePoint Online Workflows
Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
-
Upload
michael-blumenthal -
Category
Technology
-
view
169 -
download
1
Transcript of Introduction to PowerShell (SharePoint Fest Chicago 2016 Workshop)
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Introduction to PowerShell
MICHAEL BLUMENTHAL AND JACK FRUH
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Who is Michael Blumenthal?
• Technical Solution Evangelist at PSC Group
• Office 365 MVP
• Dev/ITPro Mix
• In IT Consulting since 1995
• PowerShelling since 2007
We’re
Hiring!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Who is Jack Fruh?
• Cloud Architect• Fortune 500 Company
• Big on community• SPS Chicago Suburbs
Co-Leader• SharePointJack.com• SharePoint-
Community.org
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
This is about you
• Everyone have a laptop with you?
• Do you have PowerShell installed?
• Anyone used PowerShell before?
• Who’s done scripting before?
• Admin or Developer?
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Introduce Yourself
• Your Name• Company Size• Your Role• O365 or SharePoint On Prem Version?• Where you are in your PowerShell journey• One thing you want PowerShell to solve?
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
What is PowerShell?
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Why is PowerShell AWESOME?
Write-Host “SO easy to use!”
No Compiling!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
• It’s Easy to Get Started!1• Learn the PowerShell Syntax2• Real World Examples3• Best Practices4• More Resources & Raffle5
PowerShell puts .NET at your fingertips!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Chapter 1
IT’S EASY TO GET STARTED!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Getting Started with PowerShell
20032008,R22012, R220167, 8, 8.1, 10
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
The Command Line Window
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Windows Feature
Win 8.x
Win 8-10
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
The Integrated Script Editor
V2
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
PowerShell V3-5 ISE
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Intellisense!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Now Run PowerShell
• $PSVerTable
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Chapter 2
LEARN THE POWERSHELL SYNTAX!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Symbols, Keywords, and Syntax! Oh My!
• Variables1• Commands2• Piping3• Comparisons4• Flow Control5• Filtering6
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Reading Symbols in Code
• (tal Guidance• Moe, Larry, and }• The universe started with the Big !• !Important• A # of Bacon and # Browns
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Variables
• Case Insensitive, Dynamic typing
$something
$true, $false, $null, $profile
$myMessage= “Hello, World”
1
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Create a Variable• Assign something to it• Get its value
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Commands are called cmdlets.
Verb-Noun
Built-in, Extensible
Get-Help
Get-Member
Get-Command
2
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Help!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Get-Help About_<CTRL+Space>
Discoverability
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Get-Command
• Find Cmdlets• Get details of cmdlets and applications
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Get-command get-date• Get-date | Get-member• Name a method!
• Get-command *SPO*
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Our Turn
• Get-help• Get-command –noun• Get-member
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Aliases
Alias• Dir• Sort• Select• Foreach, also %
cmdlet• Get-ChildItem• Sort-object• Select-object• Foreach-object
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Get-Alias
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
The Power of Piping!
Output Of Command
1
Input of Command
2|
3
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Example
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Pipe Demo!
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Get-ChildItem | select –first 10
• Get-ChildItem| select -first 10 | Sort-Object -Property LastAccessTime | Select-Object -Property LastAccessTime, Name
• •
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Dial zero for an…4
Operator
-eq -le-ne -like-gt -notlike-ge -match-lt -notmatch
Example
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
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
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Example
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Comparisons• Arrays and Loops
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Where-Object
•Where {<Test>}Syntax
• V1&2: Dir | Where {$_.Name –like “B*”}
• V3+: Dir | where Name –like B*
Example
6
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Your Turn
• Where
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Executing Scripts
.\filename.ps1
Set-ExecutionPolicy Unrestricted
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Use Functions
Function global:Do-Something(){}
Function global:Do-Something($someParameter){}
Function global:Do-Something{param ([type]$someParameter=$(“Default Expression”))
}
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Follow the Naming Convention!
Verb-Noun
• 98 Verbs
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Modules
• .ps1m• Profile Path - $Profile• $env:PSModulePath
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Chapter 3
CONNECTING TO SP AND O365
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
SharePoint On Prem
• SharePoint On Prem• SharePoint Management Console• 15 Hive POSH Script
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Office 365
• SharePoint Online Management Console• Office Dev PnP PowerShell• Connect-SPOService
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
DEMO – SPO Sites
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Parking Lot Question Check
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Chapter 4
REAL WORLD EXAMPLES
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Jack’s Scripts
• Examples
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Real World Examples
• Dell Service Tag• Flashcards• Audio Alerts• File Conversion & Text
Manipulation• Managing Servers at Scale
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Flash Cards
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Get-DellServiceTag
• Get-WmiObject win32_SystemEnclosure | select serialnumber
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Audio Alerts
• Stick this at the end of your long running script:
$Voice = new-object -com SAPI.SpVoice $Voice.Speak(“Deployment is done!")
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
File and Text Wrangling
• Word• AutoDOCX
• RegEx• PSObjTXT
• Export-• CSVCSV
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Server Management
Server/Service Examples of What you can script
Azure Virtual Machines
Exchange Mailboxes
Office 365 Sites
SharePoint Everything
SQL Queries
Windows Server File system
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Chapter 5
BEST PRACTICES
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
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.
#>
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Search for Commands
Refresh the command list
Actions you can take
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Self Announcing Functions
…
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Source Code Control
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Always read scripts before running them
More Good Ideas
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Always read scripts before running them.Make yours safe when others don’t
More Good Ideas
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Always read scripts before running themMake yours safe when others don’tCheck for valid parameter values get-help about_Functions_Advanced_Parameters
More Good Ideas
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Always read scripts before running themMake yours safe when others don’tCheck 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
More Good Ideas
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Chapter 6
RESOURCES
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
JEFF HICKS
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Another Book:
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
TechCommunity.microsoft.com
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
PowerShell.org
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
SharePoint Jack
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Get Jack’s Cheat Sheet
http://bit.ly/poshref
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Blumenthal’s Blog: MichaelBlumenthal.me
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Interview with Don Jones
• http://www.runasradio.com/Shows/Show/505
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Contact Us
• 847-275-7247• @MichaelBL• http://bit.ly/MBB-LI• https://Michaelblumenthal.
me
• http://bit.ly/JoinChiITEvents
• [email protected]• @sharepointjack
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Script something today!
It’s Easy to Get Started!
PowerShell Syntax
More Resources
In Review…
© 2016 PSC Group, LLC© 2016 PSC Group, LLC
Raffle
Surveys
86
Feedback Please!Session Surveys via Event AppSelect “Schedule” -> Select Session -> Scroll to “Session Survey”
Download the App:Event URL https://crowd.cc/chi2016 Your App URL https://crowd.cc/s/mGoA Or search for “SharePoint Fest” in App Store
Learn from the Top SharePoint Experts
SharePoint FestChicago 2016
WWW.SHAREPOINTFEST.COM