Learn the basics of PowerShell - what it is, where it came from, and where it can take you. See how it can interact with the various Office Servers including SharePoint both on-premises and in the cloud with SharePoint Online. See how it can easily help you parse data, transform it, and then push it back to those same servers with ease. This was delivered at SharePoint Saturday Utah 2019.
3. Intro – Greg
• Experience in Aerospace, Branding & Marketing,
Energy, Healthcare, Software
• Currently Senior Software Engineer at WECC
• Co-Founder of Aritus Computer Services, L.L.C.
• President of SharePoint / Office 365
and Dynamics 365 User Groups
• Find me online:
- @goyuix
- https://www.linkedin.com/in/goyuix
- https://stackoverflow.com/cv/goyuix
( top 2% of users )
5. Agenda
•PowerShell History & Basics
•SharePoint Online
•SharePoint PnP Library
•SharePoint On-Premises
•Office Apps Automation
This Photo by Unknown Author is licensed under CC BY-NC-ND
8. Our forebears: CSH
• Hey look! A C-Shell
• We are getting closer
• Created by Bill Joy as a graduate student
at UC Berkeley in the late 1970s
• “reads commands from a file … supports
filename wildcarding, piping, here
documents, command substitution,
variables and control structures for
condition-testing and iteration” – C-Shell,
Wikipedia
This Photo by Unknown Author is licensed under CC BY-SA
9. PowerShell Origin Story:
Monad & Manifesto
• Monad: Term coined by Leibniz to represent a fundamental
unit of existence, that are combined and composed into for
a purpose
• PowerShell paper in 2002 states: “provide a powerful,
consistent, intuitive, extensible and useful set of tools”
• Game changer: Piping objects instead of text
10. PowerShell Versions
• 1.0: for XP, Vista and Server 2003
• 2.0: included in Win 7 & Server 2008
• 3.0: included in Win 8 & Server 2012
• 4.0: included in Win 8.1 & Server 2012 R2
• 5.0/5.1: include in Win 10 & Server 2016
• 6.0: Becomes PowerShell Core
12. PowerShell Basics - Variables
• Variables are labels that hold values
• Start with a dollar sign
• Values have types
• A bunch of special variables exist:
$ENV, $_, $error, etc.
13. PowerShell Basics - Piping
• The pipe character: |
•Quite literally “pipes” output from
the left side to the right as input
• Reminder: Everything is an object,
might be a string, or something else
14. PowerShell Basics - Control
•if () { } else {}
• do { } while ()
• foreach ($item in $stuff) {}
• $stuff | ForEach-Object { $_ }
15. SharePoint Online Management Shell
• https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-
online/connect-sharepoint-online?view=sharepoint-ps
• https://www.powershellgallery.com/packages/Microsoft.Online.Share
Point.PowerShell/
• Remember PowerShell needs elevated / admin permissions
• Install: Install-Module -Name Microsoft.Online.SharePoint.PowerShell
• Verify: Get-Module -Name Microsoft.Online.SharePoint.PowerShell
• Notes: You may need to update NuGet and trust the Gallery
16. PowerShell - SPO
$email = 'admin@tenant.com’
$url = 'https://tenant-admin.sharepoint.com'
$cred = Get-Credential $email
Connect-SPOService -Url $url -Credential $cred
• Note: If MFA is enabled, just omit the credential parameter and you
will be prompted through the authentication process
17. SharePoint Patterns and Practices (PnP)
• https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-
pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps
• “Perform complex provisioning and artifact management”
• Uses Client Side Object Model (CSOM)
• Three different versions:
• Install-Module SharePointPnPPowerShellOnline
• Install-Module SharePointPnPPowerShell2016
• Install-Module SharePointPnPPowerShell2013
20. PowerShell – On-Premises
# $Host.Runspace.ThreadOptions = "ReuseThread"
# Add-PsSnapin Microsoft.SharePoint.PowerShell
$url = 'https://your-farm.domain.local’
$site = Get-SPSite $url
$site.AllWebs | Select-Object Title,Url
Note: You may need to uncomment the first two lines if you are running the
script outside of the SharePoint Management Shell (it auto-includes them)
21. Office Apps Automation
• Work with your data and surface it in applications
• A few different approaches are available
• COM / .NET API
• Office OpenXML
• How would you like to work with this data?
22. PowerShell – Word Automation
# Must have Office installed, bad for servers
$word = New-Object -ComObject word.application
$word.Visible = $true
$word.Documents.Add()
24. Learning More
• Microsoft and the community have TONS of resources
• Weekly YouTube calls for PnP work
• Channel 9, docs.microsoft.com
• Pluralsight, LinkedIn Learning / Lynda.com, Udemy, others
• Let’s chat: What do you want to build?
• Contact Me: @goyuix or linkedin.com/in/goyuix
• Github: https://github.com/goyuix/presentations/