SlideShare a Scribd company logo
SharePoint Saturday
New York
July 25th, 2015
SharePoint Saturday
New York
Office 365 & PowerShell : A match made
in heaven
Sébastien Levert
Office 365 Junkie & MVP
• We appreciated you
supporting the New York
SharePoint Community!
• Diamond, Platinum, Gold, &
Silver have tables scattered
throughout
• Please visit them and inquire
about their products & services
• To be eligible for prizes make
sure to get your bingo card
stamped by ALL sponsor
SharePoint Saturday
New York
Who’s Sébastien Levert !?
Montreal, Canada negotium.com Office365 MVP
Web Developer @sebastienlevert pimpthecloud.com
PimpTheClou
d
SharePoint Saturday
New York
Agenda
• Introduction to PowerShell in Office 365
• Using PowerShell with SharePoint Online
• Using PowerShell with the Office 365 APIs
• DevOps with PowerShell in Office 365
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Getting started
• Announced at Ignite 2015
• http://powershell.office.com
• Sets of samples, scenarios, guides, …
SharePoint Saturday
New York
What do you need ?
• An Office 365 tenant
• Administrator privileges on your Office 365 tenant
• Administrator privileges on your machine running
PowerShell
• Administration modules
• Microsoft Online Services Sign-in Assistant
• Azure Active Directory Module
• SharePoint Online Module
• Skype for Business Online Module
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Connecting to SharePoint Online
• With the SharePoint Online Module
• With the SharePoint Client Side Object Model
• With the OfficeDev PowerShell Commands
• With the SharePoint REST APIs
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Getting all your Site
Collections
Demo
SharePoint Saturday
New York
Getting all your Site Collection
Get-SPOSite
Get-SPOSite –Detailed
Get-SPOSite –Detailed –Filter { Url –like “*term*” }
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Using SharePoint CSOM in PowerShell
• You have to manually get the CSOM Assemblies
• You have to manually load the CSOM Assemblies in your
PowerShell Sessions
• Ensure to have the latest bits of the CSOM Assemblies
[AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {
$_.FullName -like "*SharePoint*” –or $_.FullName –like “*Office*”
} | Select FullName
SharePoint Saturday
New York
Tips & Tricks
• Do not use SharePoint Online Management Shell
• Import the SharePoint Online PowerShell module from a
regular PowerShell session
• Load the required CSOM Assemblies before loading the
SharePoint Online Module
• Use Gary Lapointe’s Load-CSOMProperties Cmdlet.
Everyday.
SharePoint Saturday
New York
Getting the CSOM
Assemblies
Demo
SharePoint Saturday
New York
Working with the CSOM Assemblies
Import-Module C:PathPTC.O365.PowerShell.psm1
Get-ClientAssemblies –Version 16 –TargetDirectory C:assemblies
Add-ClientAssemblies –AssembliesDirectory C:assemblies
[AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {
$_.FullName -like "*SharePoint*” –or $_.FullName –like “*Office*”
} | Select FullName
SharePoint Saturday
New York
Mixing CSOM and SPO Cmdlets
• You can easily use CSOM with the SPO Cmdlets
• Use the Cmdlets to get to the Site Collection level
• Use CSOM to get into the Webs level
SharePoint Saturday
New York
Getting all the Sites of
every Site Collection
Demo
SharePoint Saturday
New York
Get all the Sites of every Site Collection
Import-Module C:PathPTC.O365.PowerShell.psm1
Import-Module Microsoft.Online.SharePoint.PowerShell
Connect-SPOService –Url https://tenant-admin.sharepoint.com
$credentials = Get-SharePointOnlineCredentials
Get-SPOSite | Where-Object { $_.Template –notlike “*EHS#0” } | ForEach-Object {
$context = Get-Context –Url $_.Url –Credentials $credentials
Get-Webs –Context $context | Select Url
}
SharePoint Saturday
New York
Export the content of
a SharePoint list
Demo
SharePoint Saturday
New York
Export the content of a SharePoint list
$credentials = Get-SharePointOnlineCredentials
$context = Get-Context –Url “https://tenant.sharepoint.com” –Credentials $credentials
$web = Get-Web -Context $context
$list = Get-List –Web $web –Title “Tasks”
$items = Get-ListContent –List $list -Fields @(“ID”, “Title”, “DueDate”)
$items | Select @{ Name = “ID”; Expression = { $_[“ID”] } },
@{ Name = “Title”; Expression = { $_[“Title”] } },
@{ Name = “DueDate”; Expression = { $_[“DueDate”] } } |
Export-CSV –Path C:Tasks.csv –NoTypeInformation –Encoding UTF8
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Working with PowerShell.Commands
• 123 new Cmdlets Delivered by Office Dev Patterns &
Practices
• Set of Cmdlets used to execute CSOM against SharePoint
Online & On-Premises
• Uses the OfficeDevPnP.Core framework
• Needs to be installed on your machine (more complex
than a simple module)
• The real power of PowerShell with the PnP enhanced
power of CSOM
SharePoint Saturday
New York
Adding and setting a
new theme to a site
Demo
SharePoint Saturday
New York
Adding and setting a new theme to a
site
Connect-SPOnline –Url https://tenant.sharepoint.com
Add-SPOFile –Path C:theme.spcolor –Folder “_catalogs/theme/15”
Add-SPOFile –Path C:image.jpg –Folder “SiteAssets”
Set-SPOTheme `
–ColorPaletteUrl “/_catalogs/theme/15/theme.spcolor ” `
-BackgroundImageUrl “/SiteAssets/image.jpg”
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Working with REST and SharePoint
Online• Awesome series of articles by Gary Lapointe
• Magic Function provided  Invoke-SPORestMethod
• Easily use “typed” objects in your PowerShell scripts
• Remember to escape your $
SharePoint Saturday
New York
Query list items with
OData
Demo
SharePoint Saturday
New York
Query list items with Odata
$url =
“https://tenant.sharepoint.com/_api/lists/GetByTitle('Tasks')/ite
ms?`$select=Id,Title,DueDate,PercentComplete&`$filter=PercentComp
lete gt 0.5”
$items = Invoke-SPORestMethod –Url $url
$items.results | Out-GridView
SharePoint Saturday
New York
Use the search REST
API to query the
Graph
Demo
SharePoint Saturday
New York
Using the REST API to query Office
Graph
$url =
“https://tenant.sharepoint.com/_api/search/query?Querytext=‘*’&Pr
operties='GraphQuery:ACTOR(ME)’&RowLimit=100”
$results = Invoke-SPORestMethod –Url $url
$results = Get-RestSearchResults –Results $results | Out-GridView
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
Office 365 APIs
• Set of APIs delivered to unify the workloads APIs
• Built on top of Azure Active Directory Applications
• Uses OAuth and JWT for every API call
• Enables delegated permissions & App-Only permissions
• Give permissions on the needed workloads
• When the plumbing is done, it becomes very easy to use
SharePoint Saturday
New York
Steps to Office 365 API with PowerShell
1. Create an Azure Active Directory Application
2. Create a local certificate
3. Import the certificate data into your Azure AD
Application configuration
4. Use the certificate with its password in your PowerShell
code
5. Connect to the Office 365 API
6. Play with your data!
SharePoint Saturday
New York
Getting ready
Demo
SharePoint Saturday
New York
Getting ready
makecert -r -pe -n "CN=PowerShell Office 365 API Application" -b
1/01/2015 -e 12/31/2016 -ss my -len 2048
$keyCredentials = Get-KeyCredentialsManifest –Path
C:Certificate.cer
SharePoint Saturday
New York
Get an Access Token
Demo
SharePoint Saturday
New York
Get an Access Token
$global:AzureADApplicationTenantId = “TENANTID”
$global:AzureADApplicationClientId = “APPLICATIONID”
$global:AzureADApplicationCertificatePath = “C:Certificate.pfx”
$global:AzureADApplicationCertificatePassword = “Passw0rd”
$exchangeResourceUri = “https://outlook.office365.com/”
$token = Get-AccessToken -ResourceUri $exchangeResourceUri
SharePoint Saturday
New York
Get the content of
your Mailbox
Demo
SharePoint Saturday
New York
Get the content of your Mailbox
$url = $exchangeResourceUri + “/api/v1.0/users(‘email’)/folders/inbox/messages?$top=50"
$response = Invoke-SecuredRestMethod -Method "GET" -AccessToken $token -EndpointUri $url
$hasMore = $true
$messages = @()
while($hasMore) {
$response = Invoke-SecuredRestMethod -Method "GET" -AccessToken $token-EndpointUri $url
$response.value | ForEach-Object { $messages += $_ }
$hasMore = $response.'@odata.nextLink' -ne $null
$url = $response.'@odata.nextLink’
}
$messages | Select Subject | Out-GridView
SharePoint Saturday
New York
Send an Email
Demo
SharePoint Saturday
New York
Prepare the body
$body = @{
“Message” = @{
“Subject” = "This is a test email from PowerShell!”
“Body” = @{ “ContentType” = “Text”; “Content” = “This email was sent from PowerShell
using the Office 365 API.” }
“ToRecipients” = @(
@{ “EmailAddress” = @{ “Address” = “slevert@sebastienlevert.com” } }
)
}
$body.SaveToSentItems = $false
}
SharePoint Saturday
New York
Send an Email
$url = $exchangeResourceUri + “/api/v1.0/users(‘email’)/sendmail”
$response = Invoke-SecuredRestMethod –Method “POST” -AccessToken $token -EndpointUri $url
–Body ($body | ConvertTo-Json $body –Depth 4)
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
First… What is DevOps ?
• DevOps (a clipped compound of “development” and
“operations”) is a software development method that
stresses communication, collaboration, integration,
automation and measurement of cooperation between
software developers and other information-technology (IT)
professionals.
SharePoint Saturday
New York
What it means to me…
• Automate everything you can
• Ensure that every configuration can be replicated
anywhere at any time
• Gain a maximum of control over your deployments
• Are you scared of your users ?
SharePoint Saturday
New York
In the Office 365 world, it means…
• Every artifact that is created needs to be scripted or
automatically provisioned
• Users
• Mailboxes
• SharePoint
• Sites
• Columns
• Content Types
• Lists
• …
• …
SharePoint Saturday
New York
Export SharePoint site
configuration
Demo
SharePoint Saturday
New York
Export SharePoint site configuration
Connect-SPOnline –Url https://tenant.sharepoint.com
Get-SPOProvisioningTemplate –Out C:template.xml -
PersistComposedLookFiles
SharePoint Saturday
New York
Import SharePoint site
configuration
Demo
SharePoint Saturday
New York
Import SharePoint site configuration
Connect-SPOnline –Url https://tenant.sharepoint.com
Apply-SPOProvisioningTemplate –Path C:template.xml
Office 365 & PowerShell - A match made in heaven
SharePoint Saturday
New York
PowerShell for Office 365 Resources
• PowerShell for Office 365
• http://powershell.office.com
• Microsoft Online Services Sign-In Assistant for IT
Professionals
• http://www.microsoft.com/en-us/download/details.aspx?id=41950
• SharePoint Online Management Shell
• http://www.microsoft.com/en-us/download/details.aspx?id=35588
• Windows PowerShell Module for Skype for Business Online
• http://www.microsoft.com/en-us/download/details.aspx?id=39366
SharePoint Saturday
New York
PowerShell for Office 365 Resources
• Azure Active Directory Module for Windows PowerShell
• http://go.microsoft.com/fwlink/p/?linkid=236298 (32-bit Version)
• http://go.microsoft.com/fwlink/p/?linkid=236297 (64-bit Version)
• OfficeDevPnP.PowerShell Commands
• https://github.com/OfficeDev/PnP/tree/master/Solutions/PowerShell.Commands
• PimpTheCloud PowerShell Office 365 Modules
• https://github.com/PimpTheCloud/PTC.O365.PowerShell
SharePoint Saturday
New York
PowerShell for Office 365 Resources
• Gary Lapointe “PowerShell and SharePoint Online REST”
articles
• http://www.itunity.com/article/sharepoint-rest-service-windows-powershell-1381
• http://www.itunity.com/article/custom-windows-powershell-function-sharepoint-
rest-service-calls-1985
• http://www.itunity.com/article/working-lists-list-items-sharepoint-rest-service-
windows-powershell-2077
• http://www.itunity.com/article/working-folders-files-sharepoint-rest-service-
powershell-2159
SharePoint Saturday
New York
Catch me !
Montreal, Canada negotium.com Office365 MVP
Web Developer @sebastienlevert Web Developer
PimpTheClou
d
• We appreciated you
supporting the New York
SharePoint Community!
• Diamond, Platinum, Gold, &
Silver have tables scattered
throughout
• Please visit them and inquire
about their products & services
• To be eligible for prizes make
sure to get your bingo card
stamped by ALL sponsor

More Related Content

PPTX
Webinar - Office 365 & PowerShell : A Match Made in Heaven
PDF
REST in-practice, in practice!
PDF
Developing iOS REST Applications
PPTX
PowerShell: Through the SharePoint Looking Glass
PPTX
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
PPTX
SPSTC - PowerShell - Through the SharePoint Looking Glass
PDF
Modern websites in 2020 and Joomla
PPTX
Alfresco javascript api - Alfresco Devcon 2018
Webinar - Office 365 & PowerShell : A Match Made in Heaven
REST in-practice, in practice!
Developing iOS REST Applications
PowerShell: Through the SharePoint Looking Glass
SP24S053 Introduction to PowerShell for SharePoint Developers and Administrators
SPSTC - PowerShell - Through the SharePoint Looking Glass
Modern websites in 2020 and Joomla
Alfresco javascript api - Alfresco Devcon 2018

What's hot (20)

PPTX
It's just Skype for Business - THOTCON
PPTX
PowerShell for SharePoint Admins
PDF
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
PPTX
DevCon 2018 - 5 ways to use AWS with Alfresco
PPTX
Extending Alfresco Digital Workspace with Docusign
PDF
Spca2014 chris o brien modern share-point development - techniques for off-...
PPTX
Introduction to PowerShell for SharePoint Admins and Developers - SharePoint ...
PDF
Amazon Web Service - Basics
PDF
PowerShell for SharePoint Developers
PPTX
ASP.NET Core 1.0
PPTX
PowerShell for sharepoint 2010 administrators
PDF
Laravel Forge: Hello World to Hello Production
PPTX
Packer, Terraform, Ansible avec Azure
PDF
SymfonyCon Cluj 2017 - Symfony at OpenSky
PDF
Serverless computing henry been - continuous deployment of azure functions
PDF
Alfresco Transform Service DevCon 2019
 
PDF
Access to User Activities - Activity Platform APIs
PPTX
Alfresco Development Framework Basic
PPTX
Cd with Github Travis CI and Heroku
PPTX
Best Practices for Building WordPress Applications
It's just Skype for Business - THOTCON
PowerShell for SharePoint Admins
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
DevCon 2018 - 5 ways to use AWS with Alfresco
Extending Alfresco Digital Workspace with Docusign
Spca2014 chris o brien modern share-point development - techniques for off-...
Introduction to PowerShell for SharePoint Admins and Developers - SharePoint ...
Amazon Web Service - Basics
PowerShell for SharePoint Developers
ASP.NET Core 1.0
PowerShell for sharepoint 2010 administrators
Laravel Forge: Hello World to Hello Production
Packer, Terraform, Ansible avec Azure
SymfonyCon Cluj 2017 - Symfony at OpenSky
Serverless computing henry been - continuous deployment of azure functions
Alfresco Transform Service DevCon 2019
 
Access to User Activities - Activity Platform APIs
Alfresco Development Framework Basic
Cd with Github Travis CI and Heroku
Best Practices for Building WordPress Applications
Ad

Viewers also liked (20)

PPT
Windows Server 2008 (PowerShell Scripting Uygulamaları)
PDF
Power on, Powershell
PPT
Powershell Seminar @ ITWorx CuttingEdge Club
PDF
Practical PowerShell Programming for Professional People - Extended Edition
PPTX
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
PPTX
PowerShell Plus v4.7 Overview
PDF
PowerShell from *nix user perspective
PPT
Managing Virtual Infrastructures With PowerShell
PDF
PowerShell UIAtomation
PPTX
PowerShell 101
PPTX
Incorporating PowerShell into your Arsenal with PS>Attack
PPTX
Getting Started With PowerShell Scripting
PDF
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
PPT
Introduction to PowerShell
PPTX
Geek Sync | Using PowerShell with Python and SQL Server
PPTX
Network Mapping with PowerShell
PDF
Gray Hat PowerShell - ShowMeCon 2015
PDF
Practical PowerShell Programming for Professional People
PPTX
Workshop: PowerShell for Penetration Testers
PPTX
PowerShell 101 - What is it and Why should YOU Care!
Windows Server 2008 (PowerShell Scripting Uygulamaları)
Power on, Powershell
Powershell Seminar @ ITWorx CuttingEdge Club
Practical PowerShell Programming for Professional People - Extended Edition
Better, Faster, Stronger! Boost Your Team-Based SharePoint Development Using ...
PowerShell Plus v4.7 Overview
PowerShell from *nix user perspective
Managing Virtual Infrastructures With PowerShell
PowerShell UIAtomation
PowerShell 101
Incorporating PowerShell into your Arsenal with PS>Attack
Getting Started With PowerShell Scripting
Windows - Having Its Ass Kicked by Puppet and PowerShell Since 2012
Introduction to PowerShell
Geek Sync | Using PowerShell with Python and SQL Server
Network Mapping with PowerShell
Gray Hat PowerShell - ShowMeCon 2015
Practical PowerShell Programming for Professional People
Workshop: PowerShell for Penetration Testers
PowerShell 101 - What is it and Why should YOU Care!
Ad

Similar to Office 365 & PowerShell - A match made in heaven (20)

PPTX
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
PDF
Spsnyc 2014 o365 power shell csom
PPTX
SPSSTL - PowerShell - Through the SharePoint Looking Glass
PDF
Spsdc 2014 o365_power_shell_csom_amitv
PPTX
How to do everything with PowerShell
PPTX
SPugPt Meeting 35: Manage govern and drive adoption of share point online wit...
PDF
Gilles Pommier: Edit DevOps with PowerShell for Office 365 and SharePoint Onl...
PPTX
SPS Warsaw 2017
PDF
SharePoint Saturday New York: PowerShell for Office 365
PPTX
Managing SharePoint Anywhere with Windows PowerShell
PDF
O365Engage17 - Managing share point online end to-end with powershell
PDF
Mastering Office 365 with PowerShell - TechDays Finland 2020
PDF
SPSToronto 2015 - Managing Office365 with PowerShell and CSOM
PDF
Basic powershell scripts
PPTX
Spsatx slides (widescreen)
PPTX
PowerShell + SharePoint Online - An Admin's Guide
PPTX
Power Shell and Sharepoint 2013
DOCX
Windows power shell for sharepoint online & office 365
PDF
Collab365: PowerShell for Office 365
PPTX
Use PowerShell superpower to tame your Office 365
SharePoint Saturday Ottawa 2015 - Office 365 and PowerShell - A match made in...
Spsnyc 2014 o365 power shell csom
SPSSTL - PowerShell - Through the SharePoint Looking Glass
Spsdc 2014 o365_power_shell_csom_amitv
How to do everything with PowerShell
SPugPt Meeting 35: Manage govern and drive adoption of share point online wit...
Gilles Pommier: Edit DevOps with PowerShell for Office 365 and SharePoint Onl...
SPS Warsaw 2017
SharePoint Saturday New York: PowerShell for Office 365
Managing SharePoint Anywhere with Windows PowerShell
O365Engage17 - Managing share point online end to-end with powershell
Mastering Office 365 with PowerShell - TechDays Finland 2020
SPSToronto 2015 - Managing Office365 with PowerShell and CSOM
Basic powershell scripts
Spsatx slides (widescreen)
PowerShell + SharePoint Online - An Admin's Guide
Power Shell and Sharepoint 2013
Windows power shell for sharepoint online & office 365
Collab365: PowerShell for Office 365
Use PowerShell superpower to tame your Office 365

More from Sébastien Levert (20)

PPTX
SharePoint Fest Chicago 2019 - Build a Full Intranet in 70 minutes
PPTX
SharePoint Fest Chicago 2019 - Building tailored search experiences in Modern...
PPTX
SharePoint Fest Chicago 2019 - From SharePoint to Office 365 Development
PPTX
ESPC19 - Supercharge Your Teams Experience with Advanced Development Techniques
PPTX
ESPC19 - Build Your First Microsoft Teams App Using SPFx
PPTX
SharePoint Fest Seattle 2019 - From SharePoint to Office 365 Development
PPTX
SharePoint Fest Seattle 2019 - Building tailored search experiences in Modern...
PPTX
SPC19 - Building tailored search experiences in Modern SharePoint
PPTX
SharePoint Fest 2019 - Build an intelligent application by connecting it to t...
PPTX
SharePoint Fest DC 2019 - Bot Framework and Microsoft Graph - Join The Revolu...
PPTX
SharePoint Fest DC 2019 - From SharePoint to Office 365 Development
PPTX
Webinar - 2020-03-24 - Build your first Microsoft Teams app using SPFx
PPTX
SPTechCon Austin 2019 - Top 10 feature trends to make you fall in love with y...
PPTX
SPTechCon Austin 2019 - From SharePoint to Office 365 development
PPTX
SharePoint Fest Chicago 2018 - From SharePoint to Office 365 development
PPTX
SharePoint Saturday Vienna 2018 - Top 10 feature trends to make you fall in l...
PPTX
SharePoint Saturday Vienna 2018 - Building a modern intranet in 60 minutes
PPTX
European SharePoint Conference 2018 - Build an intelligent application by con...
PPTX
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
PPTX
Nashville SharePoint User Group 2018 - Building a modern intranet in 60 minutes
SharePoint Fest Chicago 2019 - Build a Full Intranet in 70 minutes
SharePoint Fest Chicago 2019 - Building tailored search experiences in Modern...
SharePoint Fest Chicago 2019 - From SharePoint to Office 365 Development
ESPC19 - Supercharge Your Teams Experience with Advanced Development Techniques
ESPC19 - Build Your First Microsoft Teams App Using SPFx
SharePoint Fest Seattle 2019 - From SharePoint to Office 365 Development
SharePoint Fest Seattle 2019 - Building tailored search experiences in Modern...
SPC19 - Building tailored search experiences in Modern SharePoint
SharePoint Fest 2019 - Build an intelligent application by connecting it to t...
SharePoint Fest DC 2019 - Bot Framework and Microsoft Graph - Join The Revolu...
SharePoint Fest DC 2019 - From SharePoint to Office 365 Development
Webinar - 2020-03-24 - Build your first Microsoft Teams app using SPFx
SPTechCon Austin 2019 - Top 10 feature trends to make you fall in love with y...
SPTechCon Austin 2019 - From SharePoint to Office 365 development
SharePoint Fest Chicago 2018 - From SharePoint to Office 365 development
SharePoint Saturday Vienna 2018 - Top 10 feature trends to make you fall in l...
SharePoint Saturday Vienna 2018 - Building a modern intranet in 60 minutes
European SharePoint Conference 2018 - Build an intelligent application by con...
SharePoint Saturday Belgium 2018 - APIs, APIs everywhere!
Nashville SharePoint User Group 2018 - Building a modern intranet in 60 minutes

Recently uploaded (20)

PDF
Modernizing your data center with Dell and AMD
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Big Data Technologies - Introduction.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Encapsulation theory and applications.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Modernizing your data center with Dell and AMD
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx
A Presentation on Artificial Intelligence
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Encapsulation theory and applications.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf

Office 365 & PowerShell - A match made in heaven

  • 1. SharePoint Saturday New York July 25th, 2015 SharePoint Saturday New York Office 365 & PowerShell : A match made in heaven Sébastien Levert Office 365 Junkie & MVP
  • 2. • We appreciated you supporting the New York SharePoint Community! • Diamond, Platinum, Gold, & Silver have tables scattered throughout • Please visit them and inquire about their products & services • To be eligible for prizes make sure to get your bingo card stamped by ALL sponsor
  • 3. SharePoint Saturday New York Who’s Sébastien Levert !? Montreal, Canada negotium.com Office365 MVP Web Developer @sebastienlevert pimpthecloud.com PimpTheClou d
  • 4. SharePoint Saturday New York Agenda • Introduction to PowerShell in Office 365 • Using PowerShell with SharePoint Online • Using PowerShell with the Office 365 APIs • DevOps with PowerShell in Office 365
  • 6. SharePoint Saturday New York Getting started • Announced at Ignite 2015 • http://powershell.office.com • Sets of samples, scenarios, guides, …
  • 7. SharePoint Saturday New York What do you need ? • An Office 365 tenant • Administrator privileges on your Office 365 tenant • Administrator privileges on your machine running PowerShell • Administration modules • Microsoft Online Services Sign-in Assistant • Azure Active Directory Module • SharePoint Online Module • Skype for Business Online Module
  • 9. SharePoint Saturday New York Connecting to SharePoint Online • With the SharePoint Online Module • With the SharePoint Client Side Object Model • With the OfficeDev PowerShell Commands • With the SharePoint REST APIs
  • 11. SharePoint Saturday New York Getting all your Site Collections Demo
  • 12. SharePoint Saturday New York Getting all your Site Collection Get-SPOSite Get-SPOSite –Detailed Get-SPOSite –Detailed –Filter { Url –like “*term*” }
  • 14. SharePoint Saturday New York Using SharePoint CSOM in PowerShell • You have to manually get the CSOM Assemblies • You have to manually load the CSOM Assemblies in your PowerShell Sessions • Ensure to have the latest bits of the CSOM Assemblies [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.FullName -like "*SharePoint*” –or $_.FullName –like “*Office*” } | Select FullName
  • 15. SharePoint Saturday New York Tips & Tricks • Do not use SharePoint Online Management Shell • Import the SharePoint Online PowerShell module from a regular PowerShell session • Load the required CSOM Assemblies before loading the SharePoint Online Module • Use Gary Lapointe’s Load-CSOMProperties Cmdlet. Everyday.
  • 16. SharePoint Saturday New York Getting the CSOM Assemblies Demo
  • 17. SharePoint Saturday New York Working with the CSOM Assemblies Import-Module C:PathPTC.O365.PowerShell.psm1 Get-ClientAssemblies –Version 16 –TargetDirectory C:assemblies Add-ClientAssemblies –AssembliesDirectory C:assemblies [AppDomain]::CurrentDomain.GetAssemblies() | Where-Object { $_.FullName -like "*SharePoint*” –or $_.FullName –like “*Office*” } | Select FullName
  • 18. SharePoint Saturday New York Mixing CSOM and SPO Cmdlets • You can easily use CSOM with the SPO Cmdlets • Use the Cmdlets to get to the Site Collection level • Use CSOM to get into the Webs level
  • 19. SharePoint Saturday New York Getting all the Sites of every Site Collection Demo
  • 20. SharePoint Saturday New York Get all the Sites of every Site Collection Import-Module C:PathPTC.O365.PowerShell.psm1 Import-Module Microsoft.Online.SharePoint.PowerShell Connect-SPOService –Url https://tenant-admin.sharepoint.com $credentials = Get-SharePointOnlineCredentials Get-SPOSite | Where-Object { $_.Template –notlike “*EHS#0” } | ForEach-Object { $context = Get-Context –Url $_.Url –Credentials $credentials Get-Webs –Context $context | Select Url }
  • 21. SharePoint Saturday New York Export the content of a SharePoint list Demo
  • 22. SharePoint Saturday New York Export the content of a SharePoint list $credentials = Get-SharePointOnlineCredentials $context = Get-Context –Url “https://tenant.sharepoint.com” –Credentials $credentials $web = Get-Web -Context $context $list = Get-List –Web $web –Title “Tasks” $items = Get-ListContent –List $list -Fields @(“ID”, “Title”, “DueDate”) $items | Select @{ Name = “ID”; Expression = { $_[“ID”] } }, @{ Name = “Title”; Expression = { $_[“Title”] } }, @{ Name = “DueDate”; Expression = { $_[“DueDate”] } } | Export-CSV –Path C:Tasks.csv –NoTypeInformation –Encoding UTF8
  • 24. SharePoint Saturday New York Working with PowerShell.Commands • 123 new Cmdlets Delivered by Office Dev Patterns & Practices • Set of Cmdlets used to execute CSOM against SharePoint Online & On-Premises • Uses the OfficeDevPnP.Core framework • Needs to be installed on your machine (more complex than a simple module) • The real power of PowerShell with the PnP enhanced power of CSOM
  • 25. SharePoint Saturday New York Adding and setting a new theme to a site Demo
  • 26. SharePoint Saturday New York Adding and setting a new theme to a site Connect-SPOnline –Url https://tenant.sharepoint.com Add-SPOFile –Path C:theme.spcolor –Folder “_catalogs/theme/15” Add-SPOFile –Path C:image.jpg –Folder “SiteAssets” Set-SPOTheme ` –ColorPaletteUrl “/_catalogs/theme/15/theme.spcolor ” ` -BackgroundImageUrl “/SiteAssets/image.jpg”
  • 28. SharePoint Saturday New York Working with REST and SharePoint Online• Awesome series of articles by Gary Lapointe • Magic Function provided  Invoke-SPORestMethod • Easily use “typed” objects in your PowerShell scripts • Remember to escape your $
  • 29. SharePoint Saturday New York Query list items with OData Demo
  • 30. SharePoint Saturday New York Query list items with Odata $url = “https://tenant.sharepoint.com/_api/lists/GetByTitle('Tasks')/ite ms?`$select=Id,Title,DueDate,PercentComplete&`$filter=PercentComp lete gt 0.5” $items = Invoke-SPORestMethod –Url $url $items.results | Out-GridView
  • 31. SharePoint Saturday New York Use the search REST API to query the Graph Demo
  • 32. SharePoint Saturday New York Using the REST API to query Office Graph $url = “https://tenant.sharepoint.com/_api/search/query?Querytext=‘*’&Pr operties='GraphQuery:ACTOR(ME)’&RowLimit=100” $results = Invoke-SPORestMethod –Url $url $results = Get-RestSearchResults –Results $results | Out-GridView
  • 34. SharePoint Saturday New York Office 365 APIs • Set of APIs delivered to unify the workloads APIs • Built on top of Azure Active Directory Applications • Uses OAuth and JWT for every API call • Enables delegated permissions & App-Only permissions • Give permissions on the needed workloads • When the plumbing is done, it becomes very easy to use
  • 35. SharePoint Saturday New York Steps to Office 365 API with PowerShell 1. Create an Azure Active Directory Application 2. Create a local certificate 3. Import the certificate data into your Azure AD Application configuration 4. Use the certificate with its password in your PowerShell code 5. Connect to the Office 365 API 6. Play with your data!
  • 37. SharePoint Saturday New York Getting ready makecert -r -pe -n "CN=PowerShell Office 365 API Application" -b 1/01/2015 -e 12/31/2016 -ss my -len 2048 $keyCredentials = Get-KeyCredentialsManifest –Path C:Certificate.cer
  • 38. SharePoint Saturday New York Get an Access Token Demo
  • 39. SharePoint Saturday New York Get an Access Token $global:AzureADApplicationTenantId = “TENANTID” $global:AzureADApplicationClientId = “APPLICATIONID” $global:AzureADApplicationCertificatePath = “C:Certificate.pfx” $global:AzureADApplicationCertificatePassword = “Passw0rd” $exchangeResourceUri = “https://outlook.office365.com/” $token = Get-AccessToken -ResourceUri $exchangeResourceUri
  • 40. SharePoint Saturday New York Get the content of your Mailbox Demo
  • 41. SharePoint Saturday New York Get the content of your Mailbox $url = $exchangeResourceUri + “/api/v1.0/users(‘email’)/folders/inbox/messages?$top=50" $response = Invoke-SecuredRestMethod -Method "GET" -AccessToken $token -EndpointUri $url $hasMore = $true $messages = @() while($hasMore) { $response = Invoke-SecuredRestMethod -Method "GET" -AccessToken $token-EndpointUri $url $response.value | ForEach-Object { $messages += $_ } $hasMore = $response.'@odata.nextLink' -ne $null $url = $response.'@odata.nextLink’ } $messages | Select Subject | Out-GridView
  • 43. SharePoint Saturday New York Prepare the body $body = @{ “Message” = @{ “Subject” = "This is a test email from PowerShell!” “Body” = @{ “ContentType” = “Text”; “Content” = “This email was sent from PowerShell using the Office 365 API.” } “ToRecipients” = @( @{ “EmailAddress” = @{ “Address” = “slevert@sebastienlevert.com” } } ) } $body.SaveToSentItems = $false }
  • 44. SharePoint Saturday New York Send an Email $url = $exchangeResourceUri + “/api/v1.0/users(‘email’)/sendmail” $response = Invoke-SecuredRestMethod –Method “POST” -AccessToken $token -EndpointUri $url –Body ($body | ConvertTo-Json $body –Depth 4)
  • 46. SharePoint Saturday New York First… What is DevOps ? • DevOps (a clipped compound of “development” and “operations”) is a software development method that stresses communication, collaboration, integration, automation and measurement of cooperation between software developers and other information-technology (IT) professionals.
  • 47. SharePoint Saturday New York What it means to me… • Automate everything you can • Ensure that every configuration can be replicated anywhere at any time • Gain a maximum of control over your deployments • Are you scared of your users ?
  • 48. SharePoint Saturday New York In the Office 365 world, it means… • Every artifact that is created needs to be scripted or automatically provisioned • Users • Mailboxes • SharePoint • Sites • Columns • Content Types • Lists • … • …
  • 49. SharePoint Saturday New York Export SharePoint site configuration Demo
  • 50. SharePoint Saturday New York Export SharePoint site configuration Connect-SPOnline –Url https://tenant.sharepoint.com Get-SPOProvisioningTemplate –Out C:template.xml - PersistComposedLookFiles
  • 51. SharePoint Saturday New York Import SharePoint site configuration Demo
  • 52. SharePoint Saturday New York Import SharePoint site configuration Connect-SPOnline –Url https://tenant.sharepoint.com Apply-SPOProvisioningTemplate –Path C:template.xml
  • 54. SharePoint Saturday New York PowerShell for Office 365 Resources • PowerShell for Office 365 • http://powershell.office.com • Microsoft Online Services Sign-In Assistant for IT Professionals • http://www.microsoft.com/en-us/download/details.aspx?id=41950 • SharePoint Online Management Shell • http://www.microsoft.com/en-us/download/details.aspx?id=35588 • Windows PowerShell Module for Skype for Business Online • http://www.microsoft.com/en-us/download/details.aspx?id=39366
  • 55. SharePoint Saturday New York PowerShell for Office 365 Resources • Azure Active Directory Module for Windows PowerShell • http://go.microsoft.com/fwlink/p/?linkid=236298 (32-bit Version) • http://go.microsoft.com/fwlink/p/?linkid=236297 (64-bit Version) • OfficeDevPnP.PowerShell Commands • https://github.com/OfficeDev/PnP/tree/master/Solutions/PowerShell.Commands • PimpTheCloud PowerShell Office 365 Modules • https://github.com/PimpTheCloud/PTC.O365.PowerShell
  • 56. SharePoint Saturday New York PowerShell for Office 365 Resources • Gary Lapointe “PowerShell and SharePoint Online REST” articles • http://www.itunity.com/article/sharepoint-rest-service-windows-powershell-1381 • http://www.itunity.com/article/custom-windows-powershell-function-sharepoint- rest-service-calls-1985 • http://www.itunity.com/article/working-lists-list-items-sharepoint-rest-service- windows-powershell-2077 • http://www.itunity.com/article/working-folders-files-sharepoint-rest-service- powershell-2159
  • 57. SharePoint Saturday New York Catch me ! Montreal, Canada negotium.com Office365 MVP Web Developer @sebastienlevert Web Developer PimpTheClou d
  • 58. • We appreciated you supporting the New York SharePoint Community! • Diamond, Platinum, Gold, & Silver have tables scattered throughout • Please visit them and inquire about their products & services • To be eligible for prizes make sure to get your bingo card stamped by ALL sponsor