GithubHelp home page GithubHelp logo

spe-extended-functions's Introduction

SPE Extended Functions

The utility functions for Sitecore PowerShell.

Usage

  1. Download the package from here and install it.
  2. Declare Import-Function SpeExtendedFunctions in the top of your script.
  3. Now you can use the additional functions.

Functions

Disable-Security (Alias: sudo)

Apply the SecurityDisabler in a specified script block.

Disable-Security {
    # Able to call unauthorized process here.
}

Edit-Item (Alias: edit)

Allow item editing in a specified script block.

$item = Get-Item "/sitecore/content/Home"

Edit-Item $item {
    $item["Title"] = "New Title"
}

echo $item["Title"] # => Returns "New Title".

Get-MediaContent

Get the Media field value of a media item as string.

$media = Get-Item "/sitecore/media library/My CSV file"

Get-MediaContent -Item $media # => Returns the csv content attached to $media.

New-ItemIfNotExists

If an item does not exist in a specified path, it will be created with a specified template. If the item exists, it will be returned.

$template = Get-Item "/sitecore/templates/Sample/Sample Item"

New-ItemIfNotExists -Path "/sitecore/content/Home/New Item" -TemplateID $template.ID
# => The item will always be returned.

Resolve-Instance

Resolve an instance by interface registered in the DI container.

Resolve-Instance -TypeName Sitecore.XA.Foundation.Search.Services.IIndexResolver
# => Returns an instance of the IndexResolver.

Set-FinalWorkflow

Assign a final workflow to a specified item.

$item = Get-Item "/sitecore/content/Home"

Set-FinalWorkflow -Item $item # => Assigned the Approved state.

Set-InitialWorkflow

Assign a initial workflow to a specified item.

$item = Get-Item "/sitecore/content/Home"

Set-InitialWorkflow -Item $item # => Assigned the Draft state.

Set-MediaContent

Set a string value to the Media field of a media item.

$media = Get-Item "/sitecore/media library/My CSV file"

Set-MediaContent -Item $media -Content "New Content"

Get-MediaContent -Item $media # => Returns "New Content"

Switch-Context (Alias: sctx)

Switch Site/Database/Language/User context in a specified block. When -NoSecurity is passed, apply the SecurityDisabler.

$context = @{
    Database = "web"
    Language = "ja-JP"
    Site = "website"
    User = "sitecore\Author"
    NoSecurity = $true
}

Switch-Context @context -Script {
    [Sitecore.Context]::Database.Name # => Returns "web"
    [Sitecore.Context]::Language.Name # => Returns "ja-JP"
    [Sitecore.Context]::Site.Name     # => Returns "website"
    [Sitecore.Context]::User.Name     # => Returns "sitecore\Author"
}

Switch-Database

Apply the DatabaseSwitcher in a specified script block.

[Sitecore.Context]::Database.Name # => Returns "master"

Switch-Database "web" {
    [Sitecore.Context]::Database.Name # => Returns "web"
}

Switch-Language

Apply the LanguageSwitcher in a specified script block.

[Sitecore.Context]::Language.Name # => Returns "en"

Switch-Language "ja-JP" {
    [Sitecore.Context]::Language.Name # => Returns "ja-JP"
}

Switch-Site

Apply the SiteContextSwitcher in a specified script block.

[Sitecore.Context]::Site.Name # => Returns "shell"

Switch-Site "website" {
    [Sitecore.Context]::Site.Name # => Returns "website"
}

Switch-User

Apply the UserSwitcher in a specified script block.

[Sitecore.Context]::User.Name # => Returns "sitecore\Admin"

Switch-User "sitecore\Author" {
    [Sitecore.Context]::User.Name # => Returns "sitecore\Author"
}

Author

License

Cairngorm is licensed under the MIT license. See LICENSE.txt.

spe-extended-functions's People

Contributors

tackme31 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.