PowerShell and SharePoint
Upcoming SlideShare
Loading in...5
×
 

PowerShell and SharePoint

on

  • 1,907 views

PowerShell is a powerful scripting environment and language for developers and administrators. SharePoint 2010 has built in PowerShell administration commandlets, but you can use this powerful ...

PowerShell is a powerful scripting environment and language for developers and administrators. SharePoint 2010 has built in PowerShell administration commandlets, but you can use this powerful scripting language with any version of SharePoint. Using PowerShell, Talbott will demonstrate how you can build and deploy SharePoint sites for development, testing, proof of concepts, and production. Using an agile methodology, you will learn how to leverage PowerShell scripts for your planning and development process.

Statistics

Views

Total Views
1,907
Views on SlideShare
1,882
Embed Views
25

Actions

Likes
0
Downloads
26
Comments
0

2 Embeds 25

http://192.168.33.10 24
http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    PowerShell and SharePoint PowerShell and SharePoint Presentation Transcript

    • PowerShell and SharePoint Talbott Crowell April 28, 2012SharePoint Saturday Boston #SPSBOS http://www.thirdm.com @talbott
    • What is PowerShell?• Unix-like shell• Object oriented• .NET• Command line• Scripting language www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Why PowerShell for SharePoint?• Automated build and deploy• Rapid prototyping• Exploring “What If” scenarios• Developer onboarding• Administration automation www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • When use PowerShell?• When you want to make your team more agile – Automation, automation, automation• When developing, your daily build is like the projects heartbeat – PowerShell can be the pacemaker• Testing – Use the PowerShell scripts to stand up an environment for running tests www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • PowerShell Basics• What do you know about a command line? – DIR• How about – $a = DIR• What is $a? – .NET Object • use gm or get-member to query properites – Array • $a[0] www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Demo - Basics• PowerShell Basics – $a = DIR – $a | gm – Dates www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Tools• cmd, notepad• PowerShell Command• Windows PowerShell Integrated Scripting Environment (ISE) – Import-Module ServerManager; – Add-WindowsFeature PowerShell-ISE• PowerGUI – Download from powergui.org www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • More Basics• # for comment• Verb-Noun convention for commandlets• Write-Host “Hello World”• Set-ExecutionPolicy Unrestricted• .scriptname to execute www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • SharePoint 2010• Comes with PowerShell Commandlets – Get-SPSite – New-SPSite – New-SPWeb• If you are running from standard PowerShell Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Create Site Collections and Sites• Get-SPSite – Parameter: url• New-SPSite – Parameters: url, name, ownerAlias, template• New-SPWeb – Parameters: url, name, description, template… – Other params: • -AddToTopNav or -UseParentTopNav • -AddToQuickLaunch www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • What about MOSS 2007 or WSS?• Your friend STSADM is still there• You can call STSADM or any command line tool from PowerShell• You can write your own command line tools with .NET• Better yet, you can write your own PowerShell Commandlets! – Inherit from Cmdlet or PSCmdlet• Gary Lapointe has WSS and MOSS Cmdlets! – http://stsadm.blogspot.com/2009/02/downloads.html www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Creating SharePoint 2010 Cmdlets• When creating non-persistent tasks (i.e. get info) use: – SPCmdlet• When objects persist between commands, use: – SPRemoveCmdletBase – SPNewCmdletBase – SPSetCmdletBase – SPGetCmdletBase• For more info, see Gary Lapointe’s blog post: – http://stsadm.blogspot.com/2009/10/creating-custom- sharepoint-2010-cmdlets.html www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Creating SharePoint Objects• [void][System.Reflection.Assembly]::LoadWithPar tialName(”Microsoft.SharePoint”) – Load the assembly• $SPSite = New-Object Microsoft.SharePoint.SPSite($url) – Reference to the site collection using SharePoint object model• Don’t forget to – $SPSite.Dispose() www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Strategy• Series of scripts to build your site• Cleanup script to destroy site• Edit script, run cleanup, run script, view site – Repeat www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Demo – series of scripts• Build2010.ps1 – Calls other scripts• Build2010_site_structure.ps1 – Sets up the basic site structure and content types• Build2010_upload_file.ps1 – Uploads sample files to the site• Build2010_set_logo.ps1 – Adds site logo• Build2010_add_users.ps1 – Adds users to local machine and/or SharePoint groups www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Defining functions• function Get-Theme ([Microsoft.SharePoint.SPWeb]$SPWeb, [string]$themeName)• Strong typed parameters• Returns Microsoft.SharePoint.Utilities.ThmxTheme www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Iteration Style Scripts• Upload File – Takes in 1 or more files• Has 3 blocks – Begin – Process – End• Process is executed for each file• gci C:uploadfilesSamplesLegal | .build2010_upload_file.ps1 -Location "shared/legal" - DocLib "Documents" -ContentType "Document" - MetaDataField "Dept" -MetaDataValue "Legal" www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Other References• How to: Build a SharePoint 2010 PowerShell Cmdlet – http://silverlight.sys-con.com/node/1370916 www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
    • Thank you. Questions? PowerShell and SharePoint Talbott Crowell ThirdM.comhttp://talbottcrowell.wordpress.com/ Twitter: @talbott