Last active
December 2, 2019 04:30
-
-
Save vtml/df89ee61059d676fb47f291ad6d7fd51 to your computer and use it in GitHub Desktop.
Running RestfulV2 Powershell Scripts using Basic Authentication for Sitecore Powershell Extensions 5.1 and above
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
This script triggers any SPE scripts that are available to be used through the Restful V2 service. Sitecore Powershell Extensions 5.1 or above is required. | |
.DESCRIPTION | |
This script triggers any SPE scripts that are available to be used through the Restful V2 service. Sitecore Powershell Extensions 5.1 or above is required. This can be used on developer PC's, as well as during CI / CD process. RestfulV2 must be enabled in Sitecore Powershell Extensions for this to work. https://doc.sitecorepowershell.com/security | |
For Sitecore 9.1 and above that uses the Identity Server, Cognified.PowerShell.IdentityServer.config must be enabled. This config patch is available from SPE 5.1 and above. | |
.PARAMETER Username | |
The Sitecore username. Uses sitecore\admin by default. | |
.PARAMETER Password | |
The Sitecore user's password. Uses 'b' by default, because 'b' is cool. | |
.PARAMETER SitecoreHost | |
The Content Management Sitecore Host. eg. https://sc911xc91xp0.dev.local | |
.PARAMETER ScriptSitecoreHost | |
The SPE script located within /sitecore/system/Modules/PowerShell/Script Library, add query string parameters as the Powershell parameters | |
.INPUTS | |
None. | |
.OUTPUTS | |
None. | |
.EXAMPLE | |
PS> .\RestfulV2-BasicAuth.ps1 -SitecoreHost https://sc911xc91xp0.dev.local -ScriptSitecorePath /ce-import?offset=3&limit=2&fields=(Name,ItemPath,Id) | |
#> | |
param( | |
[string] $Username = "sitecore\admin", | |
[string] $Password = "b", | |
[Parameter(Mandatory=$true)] | |
[string] $SitecoreHost, | |
[Parameter(Mandatory=$true)] | |
[string] $ScriptSitecorePath | |
) | |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$pair = "$($Username):$($Password)" | |
$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
$basicAuthValue = "Basic $encodedCreds" | |
$headers = @{ | |
Authorization = $basicAuthValue | |
} | |
Invoke-RestMethod -Headers $headers -Uri "$SitecoreHost/-/script/v2/master$ScriptSitecorePath" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment