Skip to content

Instantly share code, notes, and snippets.

@michaellwest
michaellwest / RemotelyDownloadImage.ps1
Last active August 29, 2015 14:23
The following downloads images from the media library in the master db and dynamically detects the file extension.
# 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 July 13, 2015 18:20
The following uploads images from the filesystem to the media library in the master db.
# 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 August 29, 2015 14:25
Sitecore patch configuration to add _basetemplates to the default Lucene index. Includes sample report.
$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 July 25, 2015 18:10
The following lists all application pools in IIS and matches with their associated w3wp.exe process id.
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 August 8, 2015 01:37
Measure PowerShell command performance in SPE.
$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 September 3, 2015 23:36
The script pulls the latest list of Sitecore Marketplace modules, including the release and revision dates.
$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 September 12, 2015 17:09
Adapted the functions written by Nick Wesselman to work directly in SPE.
<#
.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 November 24, 2015 14:30
Generates a report with all Sitecore content items, excluding specific template ids.
<#
.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 November 24, 2015 14:32
Replaces all instances of the Google Analytics click event with an empty string.
$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 November 26, 2015 06:10
Trace PowerShell parameter binding.
Trace-Command -Name ParameterBinding -PSHost -Expression {
Get-Item -Path "master:\content\home"
}