180 likes | 398 Views
Automating SharePoint Tasks with PowerShell. Rick Toner MCSD, MCPD, MCITP Rick@GetSharePoint.Com Blog: http://www.getsharepoint.com/blog. Prior Version of SharePoint. Stsadm and PsConfig Command line driven text results only. SharePoint 2010+. Welcome to Automation!
E N D
Automating SharePoint Tasks with PowerShell Rick Toner MCSD, MCPD, MCITP Rick@GetSharePoint.Com Blog: http://www.getsharepoint.com/blog
Prior Version of SharePoint • Stsadm and PsConfig • Command line driven text results only
SharePoint 2010+ • Welcome to Automation! • PowerShell + SharePoint = time savings and validation!
What is Windows PowerShell? • Dynamic scripting language • Next generation commandline/scripting environment from Microsoft. • General purpose programming language
What can it do? • Automate complex, repetitive tasks • Build command line utilities • .NET Interactive Prompt • Windows Server management • SharePoint 2010+ • IIS 7.0+
Getting Started • How do I get it? • If you're using Windows 7 or Windows Server 2008 R2, you have nothing to do - it's already there. • All other versions can download it at • http://support.microsoft.com/kb/968929
Some gotchas! • Adjust PowerShell to allow script execution. • PS> Set-ExecutionPolicy Unrestricted • What if it just won't run? • http://technet.microsoft.com/en-us/library/ee176949.aspx
Cmdlets • Standardized naming scheme for cmdlets • <Verb>-<Noun> where the verb specifies the action and the noun specifies the object to operate on. • Examples • Get-Help, Remove-Item
Scripting Language: Variables • Variables are always prefixed with $ except: • gps -OutVariableProcs –ErrorVariable Err • Set-Variable FirstName 'John' • Can be loosely or strongly typed: • $a = 5 • $a = "hi" • [int]$b = 5 • $b = "hi" # Errors since $b is type int • $c = [int]"7" # Coerce string to int • Automatic variables • $null, $true, $false, $error, $?, $LastExitCode, $OFS, $MyInvocation
Scripting Language: Variables “c” indicates case sensitive Remember: Many operators start with hyphens
A better way to script! • PowerGUI Script Editor • Debugging • Variable watch (local window) • Superior scripting UI • Intellisense (Auto complete) • Snippets • Commenting out blocks
Any good resources? • First and foremost in PowerShell; of course! • PS> Get-Help (Any command) • PS> Get-Help about_Windows_PowerShell_2.0
SharePoint PowerShell Books • A++ Book! • Automating SharePoint 2010 with Windows PowerShell 2.0 • http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470939206.html
Books continued • PowerShell for Microsoft SharePoint 2010 Administrators • http://www.mhprofessional.com/product.php?isbn=0071747974 • PowerShell for SharePoint 2010 How-To • http://www.informit.com/store/product.aspx?isbn=067233559X
Questions? • Rick’s blog - http://www.getsharepoint.com/blogemail: Rick@GetSharePoint.com Twitter ID: rtonerii • Western Carolina SharePoint Users Group • Arden, March 8th, 2012http://www.GetSharePoint.com