Sitecore Powershell

Sitecore Powershell

Windows PowerShell

  • A Microsoft task automation framework that is integrated with the .NET Framework
  • Consists of a command-line shell and associated scripting language
  • Administrative tasks are performed by using cmdlets (pronounced command-lets)
  • Sets of cmdlets may be combined together into scripts
  • Data stores are made available to the PowerShell runtime by PowerShell providers
  • The PowerShell runtime can be embedded inside other applications
  • Applications with embedded PowerShell can provide custom cmdlets to automate administrative tasks

Windows PowerShell Guidelines

  • Type 'powershell' in the Search box on Windows 7 or Windows Server 2008 to launch PowerShell
  • Interface is similar in appearance to a command prompt
  • Type 'get-help' and press <Enter> to get PowerShell Help information
  • Review and address execution policy restrictions before running any scripts

Execution Policy Restrictions

  • The default PowerShell execution policy (Restricted) does not permit any unsigned scripts to run
  • Type 'get-executionpolicy' at the PowerShell prompt to determine your current execution policy
  • Type 'set-executionpolicy remotesigned' to change the execution policy to allow unsigned scripts that you write on your local computer and signed scripts from other users

IIS PowerShell

  • IIS 7.5 is already tightly integrated with PowerShell
  • A PowerShell Management Console snap-in is available to be installed on IIS 7.0
  • A Windows 7 system must be configured to access to the WebAdministration provider
    • Type 'powershell' in the search box on the Windows Start Menu to start PowerShell
    • Right-click on the PowerShell icon in the Taskbar and select 'Import System Modules'
    • Type 'cd IIS:\' in PowerShell to switch to the WebAdministration provider
    • Type 'get-help Get-*' to view a list of simple Get cmdlets for IIS

Sitecore PowerShell

  • Sitecore shared source module distributed as a standard Sitecore package
  • Adds 'PowerShell Console' to the right side of the Sitecore Start Menu
  • Displays a PowerShell window on the Sitecore desktop
  • Installs a number of cmdlets that access the Sitecore API and can help to automate common Sitecore administration tasks
  • Provides a scripting interface to Sitecore
  • Requires Sitecore CMS 6.5

Windows PowerShell Example

  • The following three commands typed in a Windows PowerShell window will display content from the specified web page on the Sitecore site:
    • PS C:\> $webClient = New-Object System.Net.WebClient
    • PS C:\> $content = $webClient.DownloadString("http://www.theinsidecorner.com/Developers.aspx")
    • PS C:\> $content.Substring(0,500)

Sitecore PowerShell Example

  • The following three commands typed in a Sitecore PowerShell window will display content from the master database on the Sitecore site:
    • PS C:\> get-PSProvider
    • PS C:\> cd master:\ 
    • PS master:\> ls

Sources