Talbott Crowell           July 28, 2012SharePoint Saturday NYC #SPSNYC     http://www.thirdm.com            @talbott
•   What is PowerShell?•   PowerShell Basics•   Tools•   PowerShell and SharePoint•   Creating SharePoint 2010 Cmdlets•   ...
•   Unix-like shell•   Object oriented•   .NET•   Command line•   Scripting language                         www.sharepoin...
• Windows PowerShell in Action   – by Bruce Payette     (designer and author of PowerShell)• Windows PowerShell 2.0  Admin...
•   Automated build and deploy•   Rapid prototyping•   Exploring “What If” scenarios•   Developer onboarding•   Administra...
• When you want to make your team more  agile  – Automation, automation, automation• When developing, your daily build is ...
• What do you know about a command line?  – DIR• How about  – $a = DIR• What is $a?  – .NET Object     • use gm or get-mem...
• PowerShell Basics  – $a = DIR  – $a | gm  – Dates                      www.sharepointsaturday.org/boston::WEB           ...
• cmd, notepad• PowerShell Command• Windows PowerShell Integrated Scripting  Environment (ISE)  – Import-Module ServerMana...
•   # for comment•   Verb-Noun convention for commandlets•   Write-Host “Hello World”•   Set-ExecutionPolicy Unrestricted•...
• Comes with PowerShell Commandlets  – Get-SPSite  – New-SPSite  – New-SPWeb• If you are running from standard  PowerShell...
• Get-SPSite  – Parameter: url• New-SPSite  – Parameters: url, name, ownerAlias, template• New-SPWeb  – Parameters: url, n...
• Your friend STSADM is still there• You can call STSADM or any command line tool  from PowerShell• You can write your own...
• When creating non-persistent tasks (i.e. get info)  use:   – SPCmdlet• When objects persist between commands, use:   –  ...
• [void][System.Reflection.Assembly]::LoadWith  PartialName(”Microsoft.SharePoint”)  – Load the assembly• $SPSite = New-Ob...
• Series of scripts to build your site• Cleanup script to destroy site• Edit script, run cleanup, run script, view  site  ...
• Build2010.ps1   – Calls other scripts• Build2010_site_structure.ps1   – Sets up the basic site structure and content typ...
• function Get-Theme  ([Microsoft.SharePoint.SPWeb]$SPWeb,   [string]$themeName)• Strong typed parameters• Returns  Micros...
• Upload File   – Takes in 1 or more files• Has 3 blocks   – Begin   – Process   – End• Process is executed for each file•...
• Windows PowerShell in Action   – by Bruce Payette     (designer and author of PowerShell)• Windows PowerShell 2.0  Admin...
• How to: Build a SharePoint 2010 PowerShell Cmdlet   – http://silverlight.sys-con.com/node/1370916• Microsoft TechNet   –...
• Please remember to turn in your filled out  bingo cards and event evaluations for prizes.• SharePint is sponsored by Sum...
Thanks to Our Sponsors!
Talbott Crowell           ThirdM.comhttp://talbottcrowell.wordpress.com/         Twitter: @talbott
Upcoming SlideShare
Loading in...5
×

PowerShell and SharePoint @spsnyc July 2012

1,946

Published on

Published in: Technology, Business
1 Comment
0 Likes
Statistics
Notes
  • Be the first to like this

No Downloads
Views
Total Views
1,946
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
14
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

PowerShell and SharePoint @spsnyc July 2012

  1. 1. Talbott Crowell July 28, 2012SharePoint Saturday NYC #SPSNYC http://www.thirdm.com @talbott
  2. 2. • What is PowerShell?• PowerShell Basics• Tools• PowerShell and SharePoint• Creating SharePoint 2010 Cmdlets• Iteration Style Scripts www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
  3. 3. • 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
  4. 4. • Windows PowerShell in Action – by Bruce Payette (designer and author of PowerShell)• Windows PowerShell 2.0 Administrators Pocket Consultant – By William R. Stanek www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
  5. 5. • 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
  6. 6. • 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
  7. 7. • 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
  8. 8. • 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
  9. 9. • 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
  10. 10. • # 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
  11. 11. • 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
  12. 12. • 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
  13. 13. • 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
  14. 14. • 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
  15. 15. • [void][System.Reflection.Assembly]::LoadWith PartialName(”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
  16. 16. • 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
  17. 17. • 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
  18. 18. • 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
  19. 19. • 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
  20. 20. • Windows PowerShell in Action – by Bruce Payette (designer and author of PowerShell)• Windows PowerShell 2.0 Administrators Pocket Consultant – By William R. Stanek www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
  21. 21. • How to: Build a SharePoint 2010 PowerShell Cmdlet – http://silverlight.sys-con.com/node/1370916• Microsoft TechNet – http://technet.microsoft.com/en-us/library/bb978526 www.sharepointsaturday.org/boston::WEB http://www.thirdm.com WEB http://talbottcrowell.wordpress.com::EMAIL SPSBoston@live.com BLOG @talbott : TWITTER @SPSBoston / #SPSBos : TWITTER
  22. 22. • Please remember to turn in your filled out bingo cards and event evaluations for prizes.• SharePint is sponsored by Summit 7 Systems across the way at the Hilton NYC.• Follow SharePoint Saturday New York City on Twitter @spsnyc and hashtag #spsnyc 22 | SharePoint Saturday New York City 2011
  23. 23. Thanks to Our Sponsors!
  24. 24. Talbott Crowell ThirdM.comhttp://talbottcrowell.wordpress.com/ Twitter: @talbott
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×