POWERSHELL (& SHAREPOINT) This ain t your momma s command line!
JAMYE FEW SENIOR CONSULTANT 12+ years as IT Professional ( IT PRO duck DEV ) A little IT PRO, little more DEV and a lot of ducking. Certifiable in SharePoint and.net development @S7JFew http://summit7systems.com/blogs/
Summit 7 systems is a premier provider of consulting and implementation services specializing on the Microsoft SharePoint Platform and FAST Enterprise Search.» Summit 7 Systems was chosen by KMWorld Magazine as one of the top 100 Companies that Matter in Knowledge Management along with companies such as Microsoft, Oracle and IBM.» Summit 7 Systems was named to the 2011 and 2012 CRN Next-Gen 250 List as a company bringing innovative processes, methodologies and models to the solution provider industry.» Top 1% of Microsoft Partners Worldwide» Summit 7 Systems was named #6 on the 2012 CRN Fast Growth 100 based on our 2009 2011 growth of over 930% per year.» ~ 50% of Technical Staff hold US Government SECRET Clearances.» Service Disabled Veteran Owned Small Business (SDVOSB).
SOFTWARE PLATFORMS FAST Enterprise Search SharePoint 2007 SharePoint 2010 SharePoint 2013 Office Platform Sitecore SOLUTION AREAS SharePoint Platform Solutions Enterprise Search Enterprise Content Management Internet / Web Content Management Extranet Solutions Intranet Solutions Business Process Management Enterprise Project Management Exchange Server SERVICES SharePoint QuickStart Information Architecture and Governance Development Upgrade and Migration Branding and Design (User Experience) Web Content Management Design and Deployment SharePoint Search Custom Workflow or Web Part Development InfoPath Forms and Workflows Performance Baselines and Best Practices Optimization Mapping Business Process to Software Platforms Cloud Services Design and Provisioning Remote Support Contracts Compliance Quickstart
FOR MORE FROM SUMMIT 7 SYSTEMS facebook.com/summit7systems @summit7systems summit 7 systems summit7systems summit7systems.com/blogs
POWERSHELL (& SHAREPOINT) This ain t your momma s command line!
POWERSHELL (& SHAREPOINT) Hey, look here, this ain t your momma s command line, Jack! (-Si Robertson)
AGENDA What is PowerShell? STSADM?...LOL What are the benefits of PowerShell? What commands will get me started? Variables and Operators A bunch of other stuff Questions
POWER (RANGER) (TURTLE) SHELL? NOT THIS
POWERSHELL THIS
OK, WHAT IS POWERSHELL EXACTLY? Microsoft's task automation framework Command Line Shell Scripting Language Built on and integrated with the.net Framework (Pretty much C# syntax with a few caveats) DOS on steroids
WHERE IS POWERSHELL? Built into Windows Server 2008 R2 and Windows 7 Older OS Windows Management Framework Start > Accessories > Windows PowerShell SharePoint 2010 Management Shell Shortcut to a profile that loads the SP2010 Provider Snapin
STSADM? Still there and still works backwards compatibility Allows for portability of existing STSADM batch files and scripts Don t use this as a crutch! You should do everything in PowerShell. PowerShell has full access to the SharePoint API from the command line STSADM to Windows PowerShell Mapping: http://technet.microsoft.com/en-us/library/ff621081.aspx
BENEFITS OF POWERSHELL Interact with.net objects directly Remoting interface Reduction in the need of some 3rd party solutions Perform administrative functions in bulk, reducing time and effort. Performance benefits for batch operations and scheduling Some SharePoint functions require the use of PowerShell: Adding Custom Solutions(2010+) Resetting the Farm Passphrase (2010+) Configuring the State Service Application (2010+) Configuring the Publishing Feature s Super User Accounts(2010+) Pretty much all Search configuration in 2013
POWERSHELL ISE Windows PowerShell Integrated Scripting Environment (ISE) Can run commands, write, test, and debug scripts Uses color-coding Only available with PS 2.0 and above Better Option (FREE): PowerGUI http://powergui.org
POWERSHELL ESSENTIALS Get-Help Set-ExecutionPolicy Get-Command (Alias=GCM) Get-Member (piped command, Alias=GM) $object GET-MEMBER (will display the object s Methods & Properties) Add-PSSnapIn [Aliases] are helpful
EXECUTION POLICY SETTINGS Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode. AllSigned - Only scripts signed by a trusted publisher can be run. RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run. Unrestricted - No restrictions; all Windows PowerShell scripts can be run. What I use in DEV: Set-ExecutionPolicy RemoteSigned
SEE THE PATTERN? PowerShell CmdLets are Verb / Noun pairs. Set-Something Get-Something Enable-Something Tons of built in Commands Spelled CMDLETS Pronounced Command-lets
ADD-PSSNAPIN PowerShell is a blank slate (to SharePoint and FAST) Use Add-PSSnapin to add functionality (SharePoint Admin Shell) Add-PSSnapin Microsoft.SharePoint.PowerShell Add-PSSnapin Microsoft.FASTSearch.PowerShell Exchange, Active Directory, SQL, etc.
DEMO
VARIABLES Begin with $ $integer = 100 $string = Hello World! $web = Get-SPWeb http://portal.com $WEB = $web = $Web (Not Case Sensitive!)
OPERATORS $integer = 100 $integer = 100+1 Write-Host $integer 101 $integer = $integer * 2 Write-Host Integer = $integer Integer = 202 Get-Help about_operators
SPECIAL VARIABLES Reserved values: $TRUE, $FALSE, $NULL $_ Current object in the Pipeline $Args Array of parameters passed to script $PsCmdLet Current CMDLET or function that is running $Pwd Current Working Directory (not Password) Get-Help about_automatic_variables for more info
COMPARISON OPERATORS Operator Name Example Result -eq Equal 3 -eq 3 True -ne Not Equal 3 -ne 3 False -lt Less Than 3 -lt 3 False -le Less Than or Equal To 3 -le 3 True -gt Greater Than 3 -gt 3 False -ge Greater Than or Equal To 3 -ge 3 True
COMPARISON OPERATORS (CONT.) Operator Example Result -like PowerShell -like *shell True -notlike Uses Wildcard -match 9 -match [0-9] True -notmatch Uses Regular Expression -contains abc, def -contains def True -notcontains Contains an element (Think array [not STRING.CONTAINS])
DEMO
LOOPING For For Each Do While Do Until
FOREACH-OBJECT Easy Enumeration in Command Line Something foreach-object { code } cls $web = Get-SPWeb http://portal.contoso.com $web.webs ForEach-Object {$_.Title}
FORMATTING Sort-Object Get-EventLog system -Newest 5 Sort-Object EventId Format-Table Format-List
SCRIPTS Allow complex command combinations Consistently repeat frequent and/or complex tasks Can be parameterized.ps1 files even though we are 2.0 $HOST.Version gets current PS version
COMMENTS We needed another comment format # for single lines #This is a comment This is not <# #> for multiple lines <# Multiple Line Comments#>
INPUT/OUTPUT Read-Host (waits for user input) $var = Read-Host Prompt Text Write-Host Writes this text to the console Write-Host $var nonewline Write-Host (3,9,27,81) separator, To write to file: >> <filename> Output-File <filename> Tee <filename>
DEMO
WHAT TO REMEMBER Set-Execution Policy Get-Help (Get-Help About) Get-Command (Alias GCM) Get-Member Add-PSSnapIn Aliases
ALWAYS HELPFUL Google MSDN TechNet PowerGUI
FOR MORE FROM SUMMIT 7 SYSTEMS facebook.com/summit7systems @summit7systems summit 7 systems summit7systems summit7systems.com/blogs
POWERSHELL (& SHAREPOINT) This ain t your momma s command line!