SharePoint Administration with PowerShell

4,490 views

Published on

Why limit yourself to STSADM? Discover the power of PowerShell 2.0 as it is used to perform advanced administrative & development tasks. This session will start with a brief introduction to PowerShell scripting and continue with a look into helpful SharePoint scripts including: filtering event and ULS logs, managing sites and users, streamlining feature development, working with the object model, and much more! Both administrators and developers will benefit from this powerful discussion.

Published in: Technology, Design
1 Comment
5 Likes
Statistics
Notes
No Downloads
Views
Total views
4,490
On SlideShare
0
From Embeds
0
Number of Embeds
257
Actions
Shares
0
Downloads
0
Comments
1
Likes
5
Embeds 0
No embeds

No notes for slide

SharePoint Administration with PowerShell

  1. 1. Using Windows PowerShell v2.0 Eric Kraus [Microsoft] [email_address] http://blogs.msdn.com/ekraus Twitter/ @erickraus AND DEVELOPMENT!
  2. 2. <ul><li>Introduction </li></ul><ul><li>What is PowerShell? </li></ul><ul><li>Variables, Operators, and Syntax, Oh my! </li></ul><ul><li>Cmdlets? Functions? or Methods? </li></ul>
  3. 3. <ul><li>LoadAssembly[“Microsoft.SharePoint”] </li></ul><ul><li>Advanced Functions </li></ul><ul><li>Additional Resources </li></ul><ul><li>Questions </li></ul>
  4. 5. <ul><li>What is PowerShell? </li></ul><ul><li>How is it different than cmd.exe? </li></ul><ul><li>What different things can I do with PowerShell? </li></ul><ul><li>Why PowerShell? </li></ul>
  5. 6. <ul><li>Built on .NET </li></ul><ul><li>“ White Box Scripting” </li></ul><ul><li>Great IDE (“ISE”) </li></ul><ul><li>.NET Cmdlets (Visual Studio) </li></ul><ul><li>Blue Background </li></ul>
  6. 7. <ul><li>Creating Variables </li></ul><ul><ul><li>$var = “something” </li></ul></ul><ul><li>Instantiating Objects </li></ul><ul><ul><li>$var = new-object System.DateTime(2009,3,14) </li></ul></ul><ul><li>Instance vs. Static Methods </li></ul><ul><ul><li>$var.ToString() [System.DateTime]::Now </li></ul></ul><ul><li>Loading Assemblies </li></ul><ul><ul><li>[System.Reflection.Assembly]:: LoadWithPartialName(“Microsoft.SharePoint”) </li></ul></ul>
  7. 8. <ul><li>Create Aliases </li></ul><ul><ul><li>Set-Alias -name “stsadm” -value “c:program files……stsadm.exe” </li></ul></ul><ul><li>Piping </li></ul><ul><ul><li>Get-Process | format-table Get-Process | ft </li></ul></ul>
  8. 9. <ul><li>For-Each </li></ul><ul><ul><li>foreach OR | % Get-Process | foreach {Write-Host $_.Name} Get-Process | % {Write-Host $_.Name} </li></ul></ul><ul><li>Format-Table </li></ul><ul><ul><li>Get-Process | ft </li></ul></ul><ul><li>Where-Object </li></ul><ul><ul><li>where OR | ? </li></ul></ul><ul><ul><li>Get-Process | where {$_.Name –like “*explore*”} </li></ul></ul><ul><ul><li>Get-Process | ? {$_.Name –like “*explore*”} </li></ul></ul><ul><li>Out-GridView </li></ul><ul><ul><li>Get-Process | Out-GridView </li></ul></ul><ul><li>Export-CSV </li></ul><ul><ul><li>Get-Process | Export-CSV –Path c:processes.csv </li></ul></ul>
  9. 10. <ul><li>Get-Alias </li></ul><ul><li>Get-ChildItem </li></ul><ul><li>Get-Date </li></ul><ul><li>Get-EventLog </li></ul><ul><li>Get-Help </li></ul><ul><li>Get-Process </li></ul><ul><li>Get-Service </li></ul><ul><li>Set-Alias </li></ul><ul><li>Set-Location </li></ul><ul><li>Write-Host </li></ul><ul><li>Stop-Process </li></ul><ul><li>Stop-Service </li></ul><ul><li>New-Object </li></ul><ul><li>ForEach-Object </li></ul><ul><li>Where-Object </li></ul>
  10. 11. <ul><li>Get-Alias [gal] </li></ul><ul><li>Get-ChildItem [dir] </li></ul><ul><li>Get-Date </li></ul><ul><li>Get-EventLog </li></ul><ul><li>Get-Help </li></ul><ul><li>Get-Process [gps] </li></ul><ul><li>Get-Service [gsv] </li></ul><ul><li>Set-Alias [sal] </li></ul><ul><li>Set-Location [cd] </li></ul><ul><li>Write-Host [write] </li></ul><ul><li>Stop-Process [spps] </li></ul><ul><li>Stop-Service [spsv] </li></ul><ul><li>New-Object </li></ul><ul><li>ForEach-Object [%] </li></ul><ul><li>Where-Object [?] </li></ul>
  11. 12. <ul><li>Set Variables and Aliases </li></ul><ul><ul><li>$SPHome= &quot;${env:CommonProgramFiles}Microsoft Sharedweb server extensions12“ </li></ul></ul><ul><ul><li>Set-Alias –name “stsadm” –value “$SPHomeinstsadm.exe” </li></ul></ul><ul><li>Load SharePoint Assemblies </li></ul><ul><ul><li>[System.Reflection.Assembly]:: LoadFrom(“$SPHomeISAPIMicrosoft.SharePoint.dll”) </li></ul></ul>
  12. 13. <ul><li>Get-SPSite [-url] </li></ul><ul><li>Get-SPWeb [-url] </li></ul><ul><li>Get-SPEventLog [-limit 5] </li></ul><ul><li>Get-SPSolutions [-name <>] </li></ul><ul><li>Get-SPUsersInEnterpriseSites </li></ul><ul><li>Dispose-SPSite </li></ul>
  13. 14. <ul><li>Create Module Features </li></ul><ul><ul><li>Create-ModuleFiles [-outputLocation] </li></ul></ul><ul><li>Reset IIS, Warm Up SharePoint </li></ul><ul><ul><li>RestartAndWarmUp-SharePoint </li></ul></ul><ul><li>Site Collection Backup </li></ul><ul><ul><li>Backup-SPSite [-url, -outputLocation] </li></ul></ul>
  14. 15. <ul><li>[CmdletBinding()] </li></ul><ul><li>$host </li></ul><ul><ul><li>ShouldProcess() </li></ul></ul><ul><ul><li>ParameterSetName </li></ul></ul><ul><ul><li>Write-Progress </li></ul></ul><ul><li>Nested Prompt </li></ul><ul><ul><li>Get-SPSite [–url, -explore] </li></ul></ul>
  15. 16. <ul><li>$profile </li></ul><ul><li>Import-Module SPoshMod </li></ul><ul><li>ScriptBlock </li></ul><ul><ul><li>$str = “write-host ‘This is a string’” </li></ul></ul><ul><ul><li>$scriptBlock = $ExecutionContext.InvokeCommand.NewScriptBlock($str) </li></ul></ul><ul><ul><li>Invoke-Command $scriptBlock </li></ul></ul><ul><li>Get-History </li></ul>
  16. 17. <ul><li>http://blogs.msdn.com/sharepoint </li></ul><ul><li>http://blogs.msdn.com/powershell </li></ul><ul><li>http:// sharepoint.microsoft.com/blogs/zach </li></ul><ul><li>http://blogs.msdn.com/ekraus </li></ul><ul><li>http://www.poshcode.org </li></ul><ul><ul><ul><li>[Steven Murawski, Hal Rottenberg, Darin Pendergraft] </li></ul></ul></ul><ul><li>http://www.codeplex.com/SPoshMod </li></ul><ul><li>http://www.nivot.org [Oisin Grehan] </li></ul><ul><li>http://www.ilovesharepoint.com [Christian Glessner] </li></ul>

×