Presentation is loading. Please wait.

Presentation is loading. Please wait.

Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows.

Similar presentations


Presentation on theme: "Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows."— Presentation transcript:

1 great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows PowerShell

2 great people, great experience, great passion Gary Lapointe Aptillon, Inc. – Director and Founding Partner – http://www.aptillon.com SharePoint MVP since January 2008 Blog: http://blog.falchionconsulting.comhttp://blog.falchionconsulting.com Twitter: @glapointe

3 great people, great experience, great passion Agenda Conditional Logic Iteration Functions and Parameters Supporting the PipeLine Scripts Error Handling Remoting

4 great people, great experience, great passion Load Snap-in For any Editor

5 great people, great experience, great passion Conditional Logic if / elseif / else if ( ) { } elseif ( ) { } else { } switch switch ( ) { { } default { } Only perform a given task when an expression evaluates to $true

6 great people, great experience, great passion Iteration While while ( ) { } Do While do { } while ( ) Do Until do { } until( ) For Loop for ( ; ; ) { } Foreach foreach ( in ) { } Warning!!! The foreach statement is not the same as the ForEach-Object cmdlet (aliased as foreach and %) Warning!!! The foreach statement is not the same as the ForEach-Object cmdlet (aliased as foreach and %)

7 great people, great experience, great passion Quick Tips Verify your conditional logic before making changes! Test your loops before making any changes within them! Watch for disposal issues when iterating through SPSite and SPWeb objects!

8 great people, great experience, great passion Abstract common/complex tasks into a reusable unit of code Name and call functions just like cmdlets: function Set-SPListVersioning($list, $enable) {…} Set-SPListVersioning $list $true Set-SPLIstVersioning -list $list -enable $true Functions function ( ) { [return [ ]] }

9 great people, great experience, great passion Function Parameters Can use either implicit or explicit parameters Implicit Example: function ($param1, $param2, $paramN) { … } Explicit Example: function () { param ( $param1, $param2 ) } Optionally prefix variable names with type information

10 great people, great experience, great passion Advanced Function Parameters With explicit parameters you can add cmdlet binding attributes function Set-SPListVersioning() { [CmdletBinding()] param ( [Parameter(Mandatory=$true, Position=0)], [ValidateNotNull()] [Microsoft.SharePoint.SPList]$List, [Parameter(Mandatory=$false, Position=1)] [switch]$Enable ) } Type help about_functions_advanced_parameters for more examples

11 great people, great experience, great passion Current object is accessible via the $_ automatic variable Supporting the PipeLine function ( ) { begin { } process { } end { } } Be Careful!! PipeLine enabled functions need extra handling when called like a normal function Be Careful!! PipeLine enabled functions need extra handling when called like a normal function

12 great people, great experience, great passion Quick Tips Best Practice: Include a Pipeline parameter and name it $InputObject Use the filter statement if begin {} and end {} are not needed:

13 great people, great experience, great passion Scripts A script is, effectively, just a function known by a file name A script can contain many different functions, but doesn’t have to have any A script can have explicit parameters, just like a function Give scripts a.ps1 file extension Load all script functions into memory using “dot source notation”

14 great people, great experience, great passion Quick Tips Be careful of scripts that execute when loaded – Use a function to wrap tasks Functions within scripts can be made available without dot sourcing by changing the scope of the function: function global: () { … }

15 great people, great experience, great passion try / catch / finally only works with V2 – Use trap statements for V1 (or just don’t use V1!) In the catch statement block, use the $_ automatic variable to access the error details The finally statement block is optional Error Handling try { } catch [error type][, [error type]] { } finally { }

16 great people, great experience, great passion WINDOWS POWERSHELL REMOTING Administering SharePoint remotely…

17 great people, great experience, great passion Remoting PowerShell Remoting uses WinRM, Microsoft’s implementation of the WS- Management protocol – WinRM allows you to run scripts against remote servers over HTTP and HTTPS Works with V2 only Requires that WinRM be enabled on both the client and the server

18 great people, great experience, great passion Enabling Remoting Run Enable-PsRemoting on the client and server machines Must Enable CredSSP – Credential Security Support Provider – Allows cmdlets to talk to SQL using the provided credentials (handles the double-hop issue) Increase the MaxMemoryPerShellMB setting on remote server (default is 150MB) – Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000 Decrease MaxShellsPerUser and MaxConcurrentUsers (default is 5) – Set-Item WSMan:\localhost\shell\MaxShellsPerUser 2 – Set-Item WSMan:\localhost\shell\MaxConcurrentUsers 2

19 great people, great experience, great passion Enabling CredSSP On the client machine – Group Policy must be edited to allow credential delegation to the target computer. Use gpedit.msc – Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Delegating Fresh Credentials – Verify that it is enabled and configured with an SPN appropriate for the target computer (WSMAN/myserver.domain.com or WSMAN/*.domain.com) – May have to similarly enable “Allow Fresh Credentials with NTLM-only Server Authentication” if the above setting does not work – Enable-WSmanCredSSP -Role Client - DelegateComputer On the server machine – Enable-WSmanCredSSP -Role Server

20 great people, great experience, great passion Running Remote Commands

21 great people, great experience, great passion Session Configurations Use Register-PSSessionConfiguration to preload SharePoint PowerShell Snap-In – Must also set threading options Use Set-PSSessionConfiguration with - ShowSecurityDescriptorUI parameter to set security Provide configuration name when calling New- PSSession

22 great people, great experience, great passion DEMO… Windows PowerShell Remoting

23 great people, great experience, great passion Summary If you plan on writing more than 2-3 lines of PowerShell then consider using a script editor Test your scripts incrementally – Validate your loops and conditionals before making changes! Consider PowerShell remoting over integrated login for common admin tasks


Download ppt "Great people, great experience, great passion Administering SharePoint with Windows PowerShell Go Beyond the Management Shell with SharePoint and Windows."

Similar presentations


Ads by Google