+ All Categories
Home > Documents > SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint –...

SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint –...

Date post: 21-Dec-2015
Category:
View: 217 times
Download: 3 times
Share this document with a friend
23
SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010
Transcript
Page 1: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

SharePoint 2010 Administration using PowerShell

Brian Caauwe

Senior Consultant – SharePoint – MCTS

March 20, 2010

Page 2: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Introduction• PowerShell Basics• PowerShell & SharePoint 2010• Demo

• Q&A

Session Agenda

Page 3: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Brian Caauwe• Consultant & Speaker

– Email: [email protected]– Blog: http://blogs.inetium.com/blogs/bcaauwe

• MCTS - SharePoint v3

Who am I?

Page 4: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• 2nd Wednesday of the Month– 9:00 – 11:30 AM

• SharePoint resources and links• Meeting Schedule• Past User Group Presentations• This Presentation

• Next Meeting – 4/14– Business Process and Digital Forms 2007 / 2010

Minnesota SharePoint User Group

www.sharepointmn.com

Page 5: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

POWERSHELL BASICS

Page 6: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• More than just a command prompt• Not Exclusive to SharePoint

– Exchange 2007– SQL 2008– More…

• Get PowerShell– Windows Server 2003 (KB926139)– Windows Server 2008 (Activate Feature)

• Tab is your friend (auto-complete)

Getting Started

Page 7: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Use .NET objects– System.String– System.Int32– Etc.

• Access Registry– cd HKLM:\System– cd HKCU:\Software

• Store Variables– $myArray = “value1”,”value2”,”value3”

• Supports Complex operations– Loops (For, While)– If / Else– Switch

• Supports Functions– Function Get-Information([string]$arg)

More PowerShell Information

Page 8: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Syntax differences– Operators

• -lt is Less than (<)• -le is Less than or Equal To (<=)• -eq is Equivalent (==)• -gt is Greater than (>)• -ge is Greater than or Equal to (>=)• -ne is Not Equal (!=)• -or is Logical Or (||)• -and is Logical And (&&)• ? is Where (Where-Object)

– Enums and Static Methods• [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.

SharePoint”)

Even More PowerShell Information

Page 9: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• File Extension (.ps1)• Running Scripts

– Call using .\script.ps1

• ExecutionPolicy minimum RemoteSigned

PowerShell Scripts

Page 10: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Output to Console (Write-Host)

• Output to File (Out-File)

PowerShell Output

Page 11: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Get-Help

• Get-Member

PowerShell Help

Page 12: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

POWERSHELL & SP 2010

Page 13: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Uses PowerShell v2.0– Allows Remote Access

• Microsoft.SharePoint.PowerShell namespace– Get-Command -pssnapin

“Microsoft.SharePoint.PowerShell” | more– Beta2 = ~535 cmdlets

• Download Help files (.chm) from my Blog• SharePoint 2010 Management Shell

– *Run as Administrator

SharePoint 2010

Page 14: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• SharePoint_Shell_Access SQL Server Role– Get-SPShellAdmin– Add-SPShellAdmin

• Need to be a local admin to run this cmdlet• Adds user to WSS_Admin_WPG

– Remove-SPShellAdmin

SharePoint Shell Administrator

Page 15: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• All Cmdlets are Object Model Based– SPSite– SPWeb– Etc…

• Start-SPAssignment / Stop-SPAssignment– Garbage Collector for Disposable objects– Can be used on variables or globally

• Use the -WhatIF parameter to see what “would” happen

SharePoint 2010 Cmdlet Basics

Page 16: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• New-SPConfigurationDatabase (replacing psconfig)

• Add-SPSolution / Deploy-SPSolution• New-SPLogFile• Get-SPLogEvent -StartTime (Get-Date).AddHours(-

2) -EndTime (Get-Date).AddMinutes(-10)

Helpful Cmdlets

Page 17: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Using the Pipe (|)– Joins statements together

• Get-SPWebApplication http://portal.company.com | Get-SPSite -Limit All | Get-SPWeb -Limit All

• Get-SPSite http://portal.company.com | Set-SPSite -SecondaryOwnerAlias DOMAIN\username

Advanced Cmdlets

Page 18: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Querying Objects– Get-SPWeb -Filter {$_.Template -eq “Blog"}– Get-SPLogEvent -StartTime (Get-Date).AddHours(-

1)| ?{$_.Correlation -eq $guid} | Select Timestamp, Category, Message

– Get-SPSite http://portal.company.com/dept/* | foreach{New-SPWeb -Url ($_.Url + "/blog") -Template Blog#0}

– Get-SPWebApplication http://portal.company.com | Get-SPSite -Limit All | Get-SPWeb -Limit All | ?{$_.WebTemplate –eq “Blog”} | Select Url, Title, WebTemplateId

More Advanced Cmdlets

Page 19: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• Run Commands on SharePoint servers– Enable-PSRemoting –force– Enable-WSManCredSSP –role Server –force– Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000

• Run Commands on local machine– Enable-PSRemoting -force– Enable-WSManCredSSP –role Client –DelegateComputer “*.domain.com or

COMPUTERNAME” –force

• Shared SPModule (\\servername\spmodule)– Zach Rosenfields’s Blog http://

sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=54

• Store Credentials in a variable– $cred = Get-Credential

• Load Modules– $env:PSModulePath = \\servername\spmodule; + $env:PSModulePath– Import-Module SPModule.misc– Import-Module SPModule.setup

Remote Scripting

Page 20: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

DEMO

Page 21: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

Q & A

Page 22: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

• TechNet – Windows PowerShell for SharePoint Server 2010– http://technet.microsoft.com/en-us/library/ee662539(offi

ce.14).aspx

• TechNet – Getting Started: Windows PowerShell for SharePoint 2010 Administrators– http://technet.microsoft.com/en-us/sharepoint/ee518673

.aspx

• Zach Rosenfield’s Blog– http://

sharepoint.microsoft.com/blogs/zach/Lists/Categories/Category.aspx?Name=PowerShell

• Brian Caauwe’s Blog– http://blogs.inetium.com/blogs/bcaauwe

References

Page 23: SharePoint 2010 Administration using PowerShell Brian Caauwe Senior Consultant – SharePoint – MCTS March 20, 2010.

A key element to your success.


Recommended