using powershell for sharepoint 2013

36
PowerShell for SharePoint 2013 Breaking Boundaries between Developers & Administrators Nik Charleboi

Upload: nikolas-charlebois-laprade

Post on 24-May-2015

268 views

Category:

Technology


4 download

DESCRIPTION

Presentation given to the SharePoint Ottawa User Group on May 29th 2014

TRANSCRIPT

Page 1: Using PowerShell for SharePoint 2013

PowerShell for SharePoint 2013

Breaking Boundaries between Developers & Administrators

Nik Charlebois

Page 2: Using PowerShell for SharePoint 2013

Nik Charlebois• Software Engineer• 8 years experience with SharePoint• MCTS SharePoint 2013 & HTML5• Full time public servant• .NET Developer• Chair of the SPOutaouais User Group• Blog: NikCharlebois.com• @NikCharlebois

Page 3: Using PowerShell for SharePoint 2013

Author« Beginning PowerShell for SharePoint 2013 »

The best shit since the Da Vinci Code- My Mom

Page 4: Using PowerShell for SharePoint 2013

Why this session?• Bridge the gap between IT Pros & Developers;

• Understand the internals mechanisms of PowerShell;

• Demonstrate how to use PowerShell on-premises & in the cloud;

• Give an overview of what the future has in store;

Page 5: Using PowerShell for SharePoint 2013

Prerequisites?• Minimum level of exposure with PowerShell;

• Minimum level of exposure with the SharePoint’s Object Model;

Page 6: Using PowerShell for SharePoint 2013

Agenda?

History PowerShell 101

vNext

Page 7: Using PowerShell for SharePoint 2013

History

Page 8: Using PowerShell for SharePoint 2013

Back in my days…STSAdm.exe• Limited tool to manage SharePoint;

• Possibility to create command line scripts using it;

• Often very slow to execute

• Considered to be an IT Pro solution

• Exclusive adminsitrative solution for SharePoint 2003

Page 9: Using PowerShell for SharePoint 2013

Same Old…Console Application (.exe)• Used the SharePoint Object Model to do administrative tasks;

• Requires a compiled solution (Visual Studio);

• Black box not allowing administrators to read its logic;

• Considered to be a developer solution;

Page 10: Using PowerShell for SharePoint 2013

Light at the End of the TunnelPowerShell• New in 2009 (SharePoint 2010 not released yet);

• Allows for hybrid solutions between the two previous alternatives;

• Still perceived as a developer’s solution;

• Need to know the SharePoint Object Model;

Page 11: Using PowerShell for SharePoint 2013

Finally!SharePoint Management Shell• SharePoint 2010 introduces shortcut methods called cmdlets to

manage SharePoint;• Ex: Get-SPWeb, Remove-SPSolution, etc.

• Very performant option compared to the previous ones;

• Considered to be a general public solution (IT);

• Language’s appearance in all Microsoft products;

Page 12: Using PowerShell for SharePoint 2013

2007 vs 20102007$site = New-Object Microsoft.SharePoint.SPSite("http://intranet")$web = $site.RootWeb

2010$web = Get-SPWeb http://localhost

Page 13: Using PowerShell for SharePoint 2013

PowerShell & SharePoint 2013• Introduces about 100 new cmdlets (compared to 2010).

• Most are related to the new search architecture;

• Now the official tool to manage SharePoint;

• Comes preinstalled since Windows Server 2008 R2;

• Used to manage Office 365;

• Integrated in most Microsoft products

Page 14: Using PowerShell for SharePoint 2013

PowerShell 101

Page 15: Using PowerShell for SharePoint 2013

How does PowerShell Work?• PowerShell is based on the .NET platform;

• Allows you to interact with objects;• Ex: Get-SPWeb returns an SPWeb object with whom we can interact;

• Allows us to use custom dynamic libraries (custom DLLs);

Page 16: Using PowerShell for SharePoint 2013

Demo #1Reservation System

Page 17: Using PowerShell for SharePoint 2013

Pushing it to the Limit• PowerShell has access to all .NET libraries;

• Possibility to use libraries handling the graphical interface elements and others;

Page 18: Using PowerShell for SharePoint 2013

Demo #2Graphical Interfaces

18

Page 19: Using PowerShell for SharePoint 2013

Interacting with SharePoint Objects• PowerShell allows us to interact with all SharePoint object types

(just like the Object Model);

• PowerShell offers predefined cmdlets for SharePoint all the way down to the web level;

• Starting at the lists level, we go back to the 2007 way of doing it;

Page 20: Using PowerShell for SharePoint 2013

Interacting with SharePoint Objects $webApp = Get-SPWebApplication

http://localhost $site = Get-SPSite http://localhost

$web = Get-SPWeb http://localhost $list = $web.Lists[‘’My List’’’]

$item $list.Items[0]

Page 21: Using PowerShell for SharePoint 2013

Demo #3Obtain all lists in a web

Page 22: Using PowerShell for SharePoint 2013

What About Office 365?• Microsoft made available the « SharePoint Online Management

Shell »

• Connects remotely to an Office 365 SharePoint Online instance;

• Includes it own set of cmdlets;

Page 23: Using PowerShell for SharePoint 2013

What About Office 365?• Office 365 offers a H-U-G-E 30 PowerShell cmdlets;

• Offers and extremely limited set of possible operations;

• We simply add an ‘o’ in the name of each object in the cmdlets;• Ex: Get-SPOSite, Set-SPOSite, etc.

Page 24: Using PowerShell for SharePoint 2013

Demo #4Rename a site on Office 365

using PowerShell

Page 25: Using PowerShell for SharePoint 2013

Interacting with SharePoint Remotely• Since SharePoint 2010, there is a Client-Side Object Model

(CSOM);

• This model comes in 3 flavours:• JavaScript• .NET• Silverlight

• Since PowerShell leverages the .NET framework…• Then 1 + 1 =…

Page 26: Using PowerShell for SharePoint 2013

Using CSOM .NET with PowerShell• Requires you to load the following moldes in your PowerShell

session:• Microsoft.SharePoint.Client• Microsoft.SharePoint.Client.Runtime

Page 27: Using PowerShell for SharePoint 2013

Demo #5Create a SharePoint public web

On Office 365 using Powershell

27

Page 28: Using PowerShell for SharePoint 2013

How to Create a PowerShell Cmdlet?• Requires coding (Visual Studio);

• Requires you to add references to the following modules:• System.Management• System.Management.Automation

• Allows us to define custom verb-noun combinations;

• Each cmdlet is its own class;

Page 29: Using PowerShell for SharePoint 2013

Demo #6Create custom Powershell

cmdlet

29

Page 30: Using PowerShell for SharePoint 2013

vNext

Page 31: Using PowerShell for SharePoint 2013

RemotingPowerShell Web Access

• New functionnality with Windows Server 2012;

• Allows us to work in a remote PowerShell session through the browser;

Page 32: Using PowerShell for SharePoint 2013

Desired State Configuration (DSC)• New with PowerShell v4 (Windows Server 2012

R2);

• Offers a mechanism to push constant configurations between different machines or servers;

• Specifies via a script how a machine needs to be configured (roles, services, etc.).

Page 33: Using PowerShell for SharePoint 2013

My Projects

Page 34: Using PowerShell for SharePoint 2013

SPPoSh• Extensions to existing cmdlets:• Get-SPList, Move-SPList, Clear-SPBlobCache, etc.

• Free & frequently updated

SPPoSh.Codeplex.com

Page 35: Using PowerShell for SharePoint 2013

PoSh Training• Youtube Channel with free PowerShell training

videos;

Page 36: Using PowerShell for SharePoint 2013

Q&A’s