Automating PowerShell with SharePoint
Upcoming SlideShare
Loading in...5
×
 

Automating PowerShell with SharePoint

on

  • 2,596 views

 

Statistics

Views

Total Views
2,596
Views on SlideShare
2,594
Embed Views
2

Actions

Likes
0
Downloads
43
Comments
0

1 Embed 2

http://www.linkedin.com 2

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

    Automating PowerShell with SharePoint Automating PowerShell with SharePoint Presentation Transcript

    • PowerShell SharePoint
      Talbott Crowell
      SPSBoston, September 25, 2010http://www.thirdm.com
    • Unix-like shell
      Object oriented
      .NET
      Command line
      Scripting language
      What is PowerShell?
    • Automated build and deploy
      Rapid prototyping
      Exploring “What If” scenarios
      Developer onboarding
      Administration automation
      Why PowerShell for SharePoint?
    • 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
      When use PowerShell?
    • 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]
      PowerShell Basics
    • PowerShell Basics
      $a = DIR
      $a | gm
      Dates
      Demo - Basics
    • Cmd, notepad
      PowerShell Command
      Windows PowerShell Integrated Scripting Environment (ISE)
      Import-Module ServerManager;
      Add-WindowsFeaturePowerShell-ISE
      PowerGUI
      Download from powergui.org
      Tools
    • # for comment
      Verb-Noun convention for commandlets
      Write-Host “Hello World”
      Set-ExecutionPolicyUnrestricted
      .scriptname to execute
      More Basics
    • Comes with PowerShell Commandlets
      Get-SPSite
      New-SPSite
      New-SPWeb
      If you are running from standard PowerShell
      Add-PSSnapinmicrosoft.sharepoint.powershell-ErrorActionSilentlyContinue
      SharePoint 2010
    • Get-SPSite
      Parameter: url
      New-SPSite
      Parameters: url, name, ownerAlias, template
      New-SPWeb
      Parameters: url, name, description, template…
      Other params:
      -AddToTopNav or -UseParentTopNav
      -AddToQuickLaunch
      Create Site Collections and Sites
    • 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 Cmdletor PSCmdlet
      Gary Lapointe has WSS and MOSS Cmdlets!
      http://stsadm.blogspot.com/2009/02/downloads.html
      What about MOSS 2007 or WSS?
    • 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
      Creating SharePoint 2010 Cmdlets
    • [void][System.Reflection.Assembly]::LoadWithPartialName(”Microsoft.SharePoint”)
      Load the assembly
      $SPSite = New-ObjectMicrosoft.SharePoint.SPSite($url)
      Reference to the site collection using SharePoint object model
      Don’t forget to
      $SPSite.Dispose()
      Creating SharePoint Objects
    • Series of scripts to build your site
      Cleanup script to destroy site
      Edit script, run cleanup, run script, view site
      Repeat
      Strategy
    • 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
      Demo – series of scripts
    • function Get-Theme([Microsoft.SharePoint.SPWeb]$SPWeb,[string]$themeName)
      Strong typed parameters
      Returns Microsoft.SharePoint.Utilities.ThmxTheme
      Defining functions
    • Upload File
      Takes in 1 or more files
      Has 3 blocks
      Begin
      Process
      End
      Process is executed for each file
      gci 'C:uploadfilesSamplesLegal' | .uild2010_upload_file.ps1 -Location "shared/legal" -DocLib "Documents" -ContentType "Document" -MetaDataField "Dept" -MetaDataValue "Legal"
      Iteration Style Scripts
    • How to: Build a SharePoint 2010 PowerShell Cmdlet
      http://silverlight.sys-con.com/node/1370916
      Other References
    • Thank you. Questions?PowerShell SharePoint
      Talbott Crowell
      ThirdM.com
      http://talbottc.spaces.live.com
      Twitter: @talbott