Building your SharePoint Farm with PowerShell Presentation Title Bill Brockbank Solution Architect – SharePoint MVP Navantis Inc. http://blog.billbrockbank.net Brian Lalancette Infrastructure Consultant TSBUG – March 16th 2011
What is Windows PowerShell? Presentation Title What is Windows PowerShell? 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!
Welcome to SharePoint PowerShell The History Presentation Title 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 2010 652 PowerShell cmdlets Superset of Administration UI* Extensible Platform In-line Discoverability Optimized for Batch Operations No support for Installing the bits
Why PowerShell Speed and Style Presentation Title 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 PowerShell Basics Presentation Title 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
Demo PowerShell “Remoting”
Presentation Title PowerShell Remoting 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” and SharePoint Presentation Title PowerShell “Remoting” and SharePoint 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 In a brief “lapse” from the “Intro to PowerShell” sections I wanted to outline some important background for those of you anxious to run your SharePoint administration commands from a remote console. Keep in mind that just running Enable-PSRemoting is not enough! There are a few unique requirements that the SharePoint environment adds to running remote commands: 1. You MUST use CredSSP authentication. Any command that talks to a SharePoint cmdlets that itself talks to SQL (which is most commands) will need to call SQL “as you”. This means you need the ability to “double hop”—which CredSSP provides. This is enabled using the “Enable-WSmanCredSSP” cmdlets. (if you don’t use this you’ll most likely see a message saying the farm does not exist or you do not have enough privledges). 2. You SHOULD increase the MaxMemoryPerShellMB value on the remote boxes which essentially limits the amount of memory that any single remote process can use. I would not recommend doing this on every box—but rather an “admin machine” that is not externally available. The default value is 150MB, which will often fail for Site Collection creation and other long-running commands. You can change this value to a larger value (in this example 1000) using the Set-Item cmdlet: Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000 You may hit other “WSman” specific configuration issues along the way—they are often specific to your domain. However, these error messages are usually quite detailed and I have found over time to always include enough information to solve the problem right away.
Presentation Title PowerShell Modules 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 SPModule for SharePoint Presentation Title PowerShell SPModule for SharePoint 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, …. PS C:\Windows\system32> gcm -Module spmodule.setup CommandType Name Definition ----------- ---- ---------- Function Disable-AllSigningCheck ... Function Disable-OfficeSigningCheck ... Function Disable-SQLSigningCheck ... Function Enable-VerboseMsiLogging ... Function Install-SharePoint ... Function Join-SharePointFarm ... Function New-SharePointFarm ... Function New-SharePointServices ... Function Start-CentralAdministration ... PS C:\Windows\system32> gcm -Module spmodule.misc Function Backup-Logs ... Function Compress-ToZip ... Function Get-RegistryKey ... Function Get-ThreadOptions ... Function Install-Assembly ... Function Set-RegistryKey ... Function Set-ThreadOptions ... Function Test-ElevatedProcess ... Function Test-SPModuleVersion ...
Presentation Title How To Use SPModule 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.setup Executing 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”
“Remoting” - SPModule 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
IntallSP2010Server.ps1 script 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
Demo SharePoint SPModule
Presentation Title Referrences 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=54 Windows 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
More Referrences 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=c575 56ff-8df0-44fd-aba6-3df01b9f80ce AutoSPInstaller http://autospinstaller.codeplex.com/
AutoSPinstaler (Brian Lalancette) Presentation Title AutoSPinstaler (Brian Lalancette)