Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / RemotelyDownloadImage.ps1
Last active Aug 29, 2015
The following downloads images from the media library in the master db and dynamically detects the file extension.
View RemotelyDownloadImage.ps1
# The following downloads an item from the media library in the master db and dynamically detects the file extension.
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://remotesitecore
Receive-MediaItem -Session $session -Path "/sitecore/media library/Images/Icons/accuracy" -Destination C:\Images\ -Force
@michaellwest
michaellwest / RemotelyUploadImage.ps1
Created Jul 13, 2015
The following uploads images from the filesystem to the media library in the master db.
View RemotelyUploadImage.ps1
# The following uploads a single image with a new name to the specified path in the media library in the master db.
$session = New-ScriptSession -Username admin -Password b -ConnectionUri http://remotesitecore
Send-MediaItem -Session $session -Path C:\Images\banner.jpg -Destination "/sitecore/media library/Images/banner.jpg"
@michaellwest
michaellwest / BaseTemplateReport.ps1
Last active Aug 29, 2015
Sitecore patch configuration to add _basetemplates to the default Lucene index. Includes sample report.
View BaseTemplateReport.ps1
$index="sitecore_master_index"
$props = @{
Parameters = @(
@{ Name="Info"; Title="Index"; Value="The report will be based on $($index)."; editor="info" },
@{
Name="searchBaseTemplate"
Value=""
Title="Base Template"
Tooltip="Index the _basetemplates field as shown here on <a href='https://github.com/SitecorePowerShell/Console/issues/424' target='_blank'>Github</a>."
@michaellwest
michaellwest / ListRunningAppPools.ps1
Created Jul 25, 2015
The following lists all application pools in IIS and matches with their associated w3wp.exe process id.
View ListRunningAppPools.ps1
Import-Module -Name WebAdministration
$appPoolsPath = "IIS:\AppPools"
foreach($appPool in Get-ChildItem -Path $appPoolsPath) {
if($appPool.state -eq "Started") {
$processes = Get-ChildItem -Path "$($appPoolsPath)\$($appPool.Name)\WorkerProcesses"
foreach($process in $processes) {
[pscustomobject]@{
"AppPool" = $appPool.Name
@michaellwest
michaellwest / MeasureCommandPerformance.ps1
Created Aug 8, 2015
Measure PowerShell command performance in SPE.
View MeasureCommandPerformance.ps1
$path = "master:\"
$identity = "admin"
$time1 = Measure-Command -Expression {
Get-ChildItem -Path $path -Recurse | Where-Object { $_.__lock -eq $identity }
}
$time2 = Measure-Command -Expression {
$query = "fast://*[@__lock='%$($identity)%']"
Get-Item -Path $Path -Query $query
@michaellwest
michaellwest / GetSitecoreMarketplaceModulesList.ps1
Created Sep 3, 2015
The script pulls the latest list of Sitecore Marketplace modules, including the release and revision dates.
View GetSitecoreMarketplaceModulesList.ps1
$VerbosePreference = "Continue"
$relpattern = "(<label>Release date:</label>\s*<span.*>(?<release>[0-9/:AMP\s]*)</span>)"
$revpattern = "(<label>Revision date:</label>\s*<span.*>(?<revision>[0-9/:AMP\s]*)</span>)"
function Get-PageContent {
param(
[string]$Link
)
@michaellwest
michaellwest / SmartPublishItems.ps1
Created Sep 12, 2015
Adapted the functions written by Nick Wesselman to work directly in SPE.
View SmartPublishItems.ps1
<#
.NOTES
Copied from Nick Wesselman's video https://www.youtube.com/watch?v=tXTbMRVF0ts
#>
function Start-Publish {
param(
[string]$Source = "master",
[string]$Target = "web"
)
@michaellwest
michaellwest / Report-Content.ps1
Created Nov 24, 2015
Generates a report with all Sitecore content items, excluding specific template ids.
View Report-Content.ps1
<#
.SYNOPSIS
Queries all pages on the site, excluding non-content items.
#>
# List of template ids to exclude from the count.
$templateIds = @(
"{29FD19B5-6F81-4829-B725-9C4279DA13CE}",
"{C3C9ED41-B476-49A9-B50C-FF8901665EA0}",
"{5A905A62-4898-44CE-96BA-EB3432BAAD91}",
@michaellwest
michaellwest / RemoveGAEventHandler.ps1
Created Nov 24, 2015
Replaces all instances of the Google Analytics click event with an empty string.
View RemoveGAEventHandler.ps1
$path = "master:\content\"
$items = Get-ChildItem -Path $path -Recurse
$fields = @("Ads","Body","Carousel","HtmlText","Left Body","Location Body","Mid Body","Quick Links and News","Search Location")
$updateCounts = @{}
$fields | ForEach-Object { $updateCounts[$_] = 0 }
foreach($item in $items) {
Write-Host "Processing $($item.Id) : $($item.Name)"
foreach($field in $fields) {
if($item.$field) {
@michaellwest
michaellwest / TraceBinding.ps1
Created Nov 26, 2015
Trace PowerShell parameter binding.
View TraceBinding.ps1
Trace-Command -Name ParameterBinding -PSHost -Expression {
Get-Item -Path "master:\content\home"
}