Bill BrockbankSolution Architect – SharePoint MVP
Navantis Inc.
http://blog.billbrockbank.net
Brian LalancetteInfrastructure Consultant
Navantis Inc.
Building your SharePoint Farm with PowerShell
TSBUG – March 16th 2011
2
An interactive command-line and task-based scripting technology.
Allows IT professionals to accelerate automation of tasks. • What about developers (or IT Pro Developers)
A single mindset for management of many different systems (e.g.: AD, Exchange, Windows and now SharePoint)• Via PowerShell Module
Extensible framework that can be embedded inside other applications – not just a command line replacement!
What is Windows PowerShell?
Welcome to SharePoint PowerShellThe History
SharePoint v1/v2 (2001-2003):No command-line interface
SharePoint 2007:STSADM: 182 Commands (MOSS)There are some community support (Gary Lapointe)but this was just away to access the SharePoint OM.
SharePoint 2010652 PowerShell cmdletsSuperset of Administration UI*Extensible PlatformIn-line DiscoverabilityOptimized for Batch OperationsNo support for Installing the bits
Why PowerShellSpeed and Style
Deal with the .NET objects directly (Any)Remoting support to your SharePoint Services Performance benefits for batch operations
Start Thread
New STSADM Execution
Start Logging
Execute Command
Load DLLs
Stop Logging
Close STSADM & Thread
Repeat
STSADM Batch Operation
Start Thread
Stop Thread
PowerShell Cmdlets in Batch
Start logging
Execute Command
Stop logging
Repeat
SharePoint PowerShellBasics
Cmdlets for “Getting, Creating, Configuring” various SharePoint Objects. For e.g.:
Sites, Site Collections, Web Applications, Service Applications and related commands
PipeBinds for “getting a unique object”Examples:
SPSitePipeBind: GUID, URL, or SPSite Object are all accepted
SPContentDatabasePipeBind: GUID, Name, or SPContentDatabase
6
DemoPowerShell “Remoting”
7
New in PowerShell V2 – Support via WinRM
Supporting in Windows Server 2008 R2 and Windows 7
A remote interaction involves 2 endpoints – Client and a Server
PowerShell depends on WinRM for transport of data between endpoints
PowerShell Remoting
8
Windows PowerShell Remoting needs to be enabled first • Windows PowerShell Remoting needs to be enabled first by calling the following
cmdlet in Windows PowerShell:• Enable-PSRemoting
You MUST use CredSSP authentication.• To enable CredSSP on the server, use the following command:• Enable-WSManCredSSP –Role Server
• To enable CredSSP on the client, use the following command: • Enable-WSManCredSSP -Role client -DelegateComputer *
Increase the MaxMemoryPerShellMB value on the remote boxes which essentially limits the amount of memory that any single remote process can use. • Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000
PowerShell “Remoting” and SharePoint
9
Microsoft has add several PowerShell Modules with Windows Server 2008 R2.• Get-Modules –ListAvaible• ADRM – Microsoft Windows Active Directory Rights Management Services Module• BestPractices – Best Practices Analyzer (BPA)• BitsTransfer –Background Intelligent Transfer Management (BITS)• ServerManger – Server Manager module • TroubleshootingPack –Microsoft Windows Troubleshooting Pack Module• WebAdministration – Web Server Administration module
• ImportSystemModules – will load all of the Modules into PowerShell
• gcm –module <Module name>• Example: gcm –module ServerManager• cmdlet Add-WindowsFeature• cmdlet Get-WindowsFeature• cmdlet Remove-WindowsFeature
PowerShell Modules
10
SPModule written by members of the SharePoint Product Group in our spare time.
Downloaded form Microsoft Download site.
The SPModule files are a sample Windows PowerShell module related to farm installation.
Not more PowerShell cmdlet’s for SharePoint
SPModule: Is a collection of PowerShell functions• 2 PowerShell Modules with 18 function:• SPMosule.Misc (9)• SPModule.Setup (9) Install-SharePoint, New-SharePointFarm,
Join-SharePointFarm, ….
PowerShell SPModule for SharePoint
11
Importing it, this can be done before you install SharePoint on the server and it cam be do remotely.Import Spmodule in to PowerShell• $env:PSModulePath = “C:\SPModule;” + $env:PSModulePath• Import-Module SPModule.misc• Import-Module SPModule.setupExecuting SPModule functions: • Install-SharePoint -SetupExePath “\\servername\SharePoint2010-Beta\
setup.exe” -PIDKey “PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY”
• New-SharePointFarm –DatabaseAccessAccount (Get-Credential DOMAIN\username) –DatabaseServer “SQL01” –FarmName “TestFarm”
• Join-SharePointFarm -DatabaseServer “SQL01” -ConfigurationDatabaseName “TestFarm_SharePoint_Configuration_Database”
• Backup-Logs -outp “$env:userprofile\Desktop\SharePointLogs.zip”
How To Use SPModule
12
One you have enable the server and clients, you can now connect to the from the client to your servers.
• Connect to the remote server “sp2010-few” the the spinst user account, you will be prompted for the accounts password. • Enter-PSSession -ComputerName sp2010-few -Authentication CredSSP
-Credential $Env:USERDOMAIN\spinst
• Run a script on the server – in this case it imports SPModule and runs the Install-SharePoint function • . 'C:\Software\SharePoint Build Scripts\InstallSP2010Server.ps1‘
• Close the remote session• Exit-PSSession
“Remoting” - SPModule
13
Set-ExecutionPolicy -ExecutionPolicy Bypass
# Import SPModule's
$env:PSModulePath = "C:\Software\SharePoint Build Scripts\SPModule;" + $env:PSModulePath
Import-Module SPModule.misc
Import-Module SPModule.setup
$InstallDirectory = "C:\Microsoft SharePoint Servers\14.0\"
$SetupExePath = "C:\Software\SharePoint Server 2010\"
$DataDirectory = $InstallDirectory + "Data"
# SharePoint Server 2010 Product Key
$PKEY = “AAAAA-12345-XTXT1-22222-BPX4E"
Install-SharePoint -InstallDirectory $InstallDirectory -DataDirectory $DataDirectory -SetupExePath $SetupExePath -PIDKey $PKEY
IntallSP2010Server.ps1 script
14
DemoSharePoint SPModule
15
Zach Rosenfield Blog http://sharepoint.microsoft.com/Blogs/zach/default.aspx Signing Your PowerShell Scripts http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=53 SPModule.HelloWorld() http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=54Windows PowerShell Remoting http://msdn.microsoft.com/en-us/library/ee706585(VS.85).aspx SharePoint 2010 with Windows PowerShell Remoting Step by Step http://blogs.msdn.com/b/opal/archive/2010/03/07/sharepoint-2010-with-windows-powershell-remoting-step-by-step.aspx
Referrences
16
SharePoint PowerShell “Remoting” Requirements http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=45 SPModule Download http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&FamilyID=c57556ff-8df0-44fd-aba6-3df01b9f80ce AutoSPInstaller http://autospinstaller.codeplex.com/
More Referrences
17
AutoSPinstaler (Brian Lalancette)