Providers

Understanding PowerShell providers and the Sitecore provider.

The provider architecture in PowerShell enables a developer to make a command like Get-Item interact with the filesystem files and folders, and then interact with the Sitecore CMS items. This is one of the most powerful concepts in PowerShell!

What is a Provider?

A provider is an adapter that makes a data store look like a drive. Think of it like this:

  • File system provider: Makes C:\ look like a navigable drive

  • Registry provider: Makes HKLM:\ look like a navigable drive

  • Sitecore provider: Makes master:\ look like a navigable drive

This means you can use the same commands (Get-Item, Get-ChildItem, etc.) to work with files, registry keys, and Sitecore items!

Available Providers

The SPE module implements a new provider that bridges the Windows PowerShell platform with the Sitecore API. The following table demonstrates the use of Get-Item for a variety of providers.

Name
Drives
Example

Alias

Alias

Get-Item -Path alias:\dir

Sitecore

core, master, web

Get-Item -Path master:\

Environment

Env

Get-Item -Path env:\HOMEPATH

FileSystem

C, D, F, H

Get-Item -Path c:\Windows

Function

Function

Get-Item -Path function:\prompt

Registry

HKLM, HKCU

Get-Item -Path hklm:\SOFTWARE

Variable

Variable

Get-Item -Path variable:\PSVersionTable

The Sitecore Provider

The most important provider for SPE is named Sitecore. This provider gives you access to Sitecore databases.

Default Provider

The default provider used by the PowerShell Console and ISE is Sitecore with the drive set to the master database.

Database Drives

The Sitecore provider exposes these databases as drives:

Path Format

Sitecore provider paths follow this format:

Examples:

Notice that the Sitecore provider supports backslashes (\) and forward slashes (/) like the Sitecore UI.

  • Correct: master:\content\home

  • Correct: master:/content/home

  • Wrong: /sitecore/content/home

Switching Between Providers

Example: The following demonstrates switching between providers using the function cd, an alias for Set-Location, while in the Console.

Working with the Sitecore Provider

Getting Items

Creating Items

Removing Items

Testing if Item Exists

Provider-Specific Features

While all providers support basic operations like Get-Item and Get-ChildItem, some have special features:

Sitecore Provider Features

File System Provider Features

Why Providers Matter

Understanding providers is crucial because:

  1. Same commands work everywhere - Learn Get-Item once, use it for files, registry, and Sitecore

  2. Path-based navigation - Everything has a path you can navigate

  3. Consistent patterns - If it works on files, it probably works on Sitecore items

  4. Powerful automation - Combine providers to move data between systems

Example: Cross-Provider Automation

Common Provider Operations

Operation
File System
Sitecore

Get item

Get-Item C:\file.txt

Get-Item master:\content\home

List children

Get-ChildItem C:\

Get-ChildItem master:\content

Create

New-Item C:\file.txt

New-Item master:\content\home\item

Remove

Remove-Item C:\file.txt

Remove-Item master:\content\home\item

Test exists

Test-Path C:\file.txt

Test-Path master:\content\home\item

Move

Move-Item C:\old.txt C:\new.txt

Move-Item master:\a master:\b

Copy

Copy-Item C:\old.txt C:\new.txt

Copy-Item master:\a master:\b

Learn More

This introduction covers the basics of the provider architecture and how to use paths in SPE.

For comprehensive details about working with the Sitecore provider (item fields, languages, versions, wildcards, performance optimization, and advanced techniques), see the complete guide: Working with Items - Providers

Next Steps

Now that you understand providers:

  1. Practice with examples: Your First Scripts

  2. Avoid common mistakes: Common Pitfalls

  3. Deep dive into items: Working with Items

  4. Read comprehensive provider docs: Providers

Last updated