KEMBAR78
Using Powershell to manage SharePoint | PPTX
Western Mass Microsoft User
Group--Using Powershell to
         Manage SharePoint    1/11/2012   1
   Craig Pilkenton
    o SharePoint Engineer at MassMutual
     • Enterprise User Group Lead
     • SharePoint Trainer




    o Western Mass Microsoft User Group: Co-Lead
      (http://mstech.org)
    o LinkedIn.com
      (http://www.linkedin.com/in/craigpilkenton)

                                    Western Mass Microsoft User
                                    Group--Using Powershell to
                                             Manage SharePoint    1/11/2012   2
   Overview: what is Windows Powershell
   What can('t) it do?
   Managing Server‟s
   Managing SharePoint
   Updating SharePoint
   Take-Away‟s




                         Western Mass Microsoft User
                         Group--Using Powershell to
                                  Manage SharePoint    1/11/2012   3
   What is Windows Powershell?
    o Powershell is the new extensible command-line shell we
      can run on any Windows Server or desktop that allows
      for automating administrative tasks, executing any other
      command-line toolset, or for calling any regular .NET
      class, including those for the SharePoint platform.
   What does this really mean?
    o Powershell allows for automating repetitive maintenance
      tasks, modularizing scripts to “snap-on” future
      functionality, built-in enumeration objects, and calling any
      other command-line or .NET object to get work done (e.g.
      FTP, file-shares, email, etc.). Everything that is queried or
      returned to us is an „object‟ that has all of the available
      properties and methods.
                                      Western Mass Microsoft User
                                      Group--Using Powershell to
                                               Manage SharePoint    1/11/2012   4
   What does Powershell look like?




                           Western Mass Microsoft User
                           Group--Using Powershell to
                                    Manage SharePoint    1/11/2012   5
   Demo : Usage and interaction




                         Western Mass Microsoft User
                         Group--Using Powershell to
                                  Manage SharePoint    1/11/2012   6
   Monitor server status & activate (Get-Service, Get-
    EventLog, dir/ls, Stop-Service, Restart-Service)
   Import/export files for processing or reports (Import-
    Csv, Export-Csv, Out-File, Copy-Item, FTP)
   Call other command-line utilities
    (STSADM.exe, RoboCopy, Team Foundation Server, WinZip)
   Instantiate .NET objects to use their functionality
    (Email, FileInfo, ArrayList, Hashtable)
   Instantiate SharePoint‟s .NET objects to manage the platform
    (Site-level, subweb-level, Document Library/List-
    level, permission-level)
   And just about anything else…
                                   Western Mass Microsoft User
                                   Group--Using Powershell to
                                            Manage SharePoint    1/11/2012   7
   Many out-of-the-box cmdlets
   Not just informational, but reaction-able
    o Get-Service
     Stop-Service and/or Restart-Service can be fired as
      logic determines
    o Get-EventLog
     Watch for certain events and then fire other
      cmdlets, applications, or cmdlets in response
    o dir/ls (Get-ChildItem)
     Can look for files existing and if not, take action to
      get or remove

                                 Western Mass Microsoft User
                                 Group--Using Powershell to
                                          Manage SharePoint    1/11/2012   8
   Demo : Monitoring our server, and reacting
    to it




                          Western Mass Microsoft User
                          Group--Using Powershell to
                                   Manage SharePoint    1/11/2012   9
   Everything returned is a SharePoint object
   A „Site‟ object is instantiated AND must be
    disposed of when finished
    o Load the Microsoft.SharePoint .NET 2.0 object into
      memory
    o Create a „New-Object‟ to store the SharePoint site
      inside of
    o Begin querying the new object for its
      properties, methods, and stored values; some of
      which may be other SharePoint objects and/or
      collections themselves

                               Western Mass Microsoft User
                               Group--Using Powershell to
                                        Manage SharePoint    1/11/2012   10
   Demo: Checking on our SharePoint
    environment




                        Western Mass Microsoft User
                        Group--Using Powershell to
                                 Manage SharePoint    1/11/2012   11
   We still have a handle to the SharePoint site
    object to manipulate
   So what does it take?
    o We open a new SubWeb object (but this can be done
      at any level)
    o Inside of our SubWeb object, create a new List
      object
    o On the new List object, create an instance of an
      item, add column-value pairs that match the
      SharePoint List,
    o Finally call the .Update() method to add new item

                              Western Mass Microsoft User
                              Group--Using Powershell to
                                       Manage SharePoint    1/11/2012   12
   Demo: Add a new Announcement to our
    SharePoint site




                       Western Mass Microsoft User
                       Group--Using Powershell to
                                Manage SharePoint    1/11/2012   13
   Powershell can manage any Microsoft server
    or platform (some actually have inherent
    cmdlets available e.g. Exchange
    2007, SQL, etc.)
   Not only is Microsoft moving all
    server/platforms to this model, many
    vendors are doing the same with their
    software packages and/or tools
   Powershell not only talks to almost any
    command-line interface, but allows for
    reflexive decisions based on that data
                         Western Mass Microsoft User
                         Group--Using Powershell to
                                  Manage SharePoint    1/11/2012   14
   Links
    o Windows Powershell Team
     http://blogs.msdn.com/powershell/
    o PowershellCommunity.org
     http://www.powershellcommunity.org/
    o Microsoft Online—Windows SharePoint Services
     http://office.microsoft.com/en-
      us/sharepointtechnology/FX100503841033.aspx




                              Western Mass Microsoft User
                              Group--Using Powershell to
                                       Manage SharePoint    1/11/2012   15

Using Powershell to manage SharePoint

  • 1.
    Western Mass MicrosoftUser Group--Using Powershell to Manage SharePoint 1/11/2012 1
  • 2.
    Craig Pilkenton o SharePoint Engineer at MassMutual • Enterprise User Group Lead • SharePoint Trainer o Western Mass Microsoft User Group: Co-Lead (http://mstech.org) o LinkedIn.com (http://www.linkedin.com/in/craigpilkenton) Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 2
  • 3.
    Overview: what is Windows Powershell  What can('t) it do?  Managing Server‟s  Managing SharePoint  Updating SharePoint  Take-Away‟s Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 3
  • 4.
    What is Windows Powershell? o Powershell is the new extensible command-line shell we can run on any Windows Server or desktop that allows for automating administrative tasks, executing any other command-line toolset, or for calling any regular .NET class, including those for the SharePoint platform.  What does this really mean? o Powershell allows for automating repetitive maintenance tasks, modularizing scripts to “snap-on” future functionality, built-in enumeration objects, and calling any other command-line or .NET object to get work done (e.g. FTP, file-shares, email, etc.). Everything that is queried or returned to us is an „object‟ that has all of the available properties and methods. Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 4
  • 5.
    What does Powershell look like? Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 5
  • 6.
    Demo : Usage and interaction Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 6
  • 7.
    Monitor server status & activate (Get-Service, Get- EventLog, dir/ls, Stop-Service, Restart-Service)  Import/export files for processing or reports (Import- Csv, Export-Csv, Out-File, Copy-Item, FTP)  Call other command-line utilities (STSADM.exe, RoboCopy, Team Foundation Server, WinZip)  Instantiate .NET objects to use their functionality (Email, FileInfo, ArrayList, Hashtable)  Instantiate SharePoint‟s .NET objects to manage the platform (Site-level, subweb-level, Document Library/List- level, permission-level)  And just about anything else… Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 7
  • 8.
    Many out-of-the-box cmdlets  Not just informational, but reaction-able o Get-Service Stop-Service and/or Restart-Service can be fired as logic determines o Get-EventLog Watch for certain events and then fire other cmdlets, applications, or cmdlets in response o dir/ls (Get-ChildItem) Can look for files existing and if not, take action to get or remove Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 8
  • 9.
    Demo : Monitoring our server, and reacting to it Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 9
  • 10.
    Everything returned is a SharePoint object  A „Site‟ object is instantiated AND must be disposed of when finished o Load the Microsoft.SharePoint .NET 2.0 object into memory o Create a „New-Object‟ to store the SharePoint site inside of o Begin querying the new object for its properties, methods, and stored values; some of which may be other SharePoint objects and/or collections themselves Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 10
  • 11.
    Demo: Checking on our SharePoint environment Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 11
  • 12.
    We still have a handle to the SharePoint site object to manipulate  So what does it take? o We open a new SubWeb object (but this can be done at any level) o Inside of our SubWeb object, create a new List object o On the new List object, create an instance of an item, add column-value pairs that match the SharePoint List, o Finally call the .Update() method to add new item Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 12
  • 13.
    Demo: Add a new Announcement to our SharePoint site Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 13
  • 14.
    Powershell can manage any Microsoft server or platform (some actually have inherent cmdlets available e.g. Exchange 2007, SQL, etc.)  Not only is Microsoft moving all server/platforms to this model, many vendors are doing the same with their software packages and/or tools  Powershell not only talks to almost any command-line interface, but allows for reflexive decisions based on that data Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 14
  • 15.
    Links o Windows Powershell Team http://blogs.msdn.com/powershell/ o PowershellCommunity.org http://www.powershellcommunity.org/ o Microsoft Online—Windows SharePoint Services http://office.microsoft.com/en- us/sharepointtechnology/FX100503841033.aspx Western Mass Microsoft User Group--Using Powershell to Manage SharePoint 1/11/2012 15