Last active
September 14, 2016 14:23
-
-
Save michaellwest/3bec0019cc788f4b90956777bb269131 to your computer and use it in GitHub Desktop.
Sitecore PowerShell Extensions Workshop - Sitecore Symposium 2016
This file contains 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
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> | |
<sitecore> | |
<powershell> | |
<services> | |
<mediaUpload> | |
<patch:attribute name="enabled">true</patch:attribute> | |
</mediaUpload> | |
<fileDownload> | |
<patch:attribute name="enabled">true</patch:attribute> | |
</fileDownload> | |
<fileUpload> | |
<patch:attribute name="enabled">true</patch:attribute> | |
</fileUpload> | |
</services> | |
</powershell> | |
</sitecore> | |
</configuration> |
This file contains 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
# Within the context of the menu, get the items from the current path. | |
# In this case the period “.” symbolizes the selected item in the tree. | |
$items = Get-ChildItem -Path . | |
# There may be zero or more items returned by the Get-ChildItem command. | |
Show-Alert -Title "The total number of immediate children is: $($items.Count)" | |
# Dialogs rendered by SPE are automatically closed when using this command. | |
Close-Window |
This file contains 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
$date = Get-Date -Format "yyyyMMdd" | |
# Skip the first file because the latest is likely locked by the worker process. | |
$log = Get-ChildItem -Path $SitecoreLogFolder\log.$($date)*.txt | | |
Sort-Object -Property LastWriteTime -Descending | | |
Select-Object -Skip 1 -First 1 | |
$log | Send-File |
This file contains 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
$tokens = @('$name', '$date', '$time', '$now') | |
$homeRoot = "master:\content\home" | |
$items = Get-ChildItem -Path $homeRoot -Recurse -WithParent | |
$matches = @() | |
foreach($item in $items) { | |
$item | Add-Member -Name InTitle -Value $false -MemberType NoteProperty | |
$item | Add-Member -Name InText -Value $false -MemberType NoteProperty | |
$foundMatch = $false | |
foreach($token in $tokens) { | |
if($item.Title.Contains($token)) { | |
$item.InTitle = $true | |
$foundMatch = $true | |
} | |
if($item.Text.Contains($token)) { | |
$item.InText = $true | |
$foundMatch = $true | |
} | |
} | |
if($foundMatch) { | |
$matches += $item | |
} | |
} | |
$props = @{ | |
InfoTitle = "Items still containing tokens" | |
InfoDescription = "Lists the items containing tokens in the Title and Text fields." | |
PageSize = 25 | |
Property = @("Name", "InTitle", "InText") | |
} | |
$matches | Show-ListView @props |
This file contains 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
$tokens = @('$name', '$date', '$time', '$now') | |
$homeRoot = "master:\content\home" | |
$items = Get-ChildItem -Path $homeRoot -Recurse -WithParent | |
$matches = @() | |
foreach($item in $items) { | |
$item | Add-Member -Name InTitle -Value $false -MemberType NoteProperty | |
$item | Add-Member -Name InText -Value $false -MemberType NoteProperty | |
$foundMatch = $false | |
foreach($token in $tokens) { | |
if($item.Title.Contains($token)) { | |
$item.InTitle = $true | |
$foundMatch = $true | |
} | |
if($item.Text.Contains($token)) { | |
$item.InText = $true | |
$foundMatch = $true | |
} | |
} | |
if($foundMatch) { | |
$matches += $item | |
} | |
} | |
# The code from here on is where the walk through line by line begins | |
$props = @{ | |
Property = @("Name", "InTitle", "InText", @{n="Updated by";e={$_."__Updated by"}}, @{n="Updated";e={$_."__Updated"}}, "ItemPath") | |
} | |
$reportsFolder = "$($SitecoreDataFolder)\reports" | |
if(-not(Test-Path -Path $reportsFolder)) { | |
New-Item -Path $reportsFolder -ItemType Directory | Out-Null | |
} | |
$reportFile = "$($reportsFolder)\Items-still-containing-tokens.csv" | |
$matches | Select-Object @props | Export-Csv -Path $reportFile -NoTypeInformation | |
$email = @{ | |
To = "pointy.haired.boss@spe.demo.com" | |
From = "guy.with.glasses@spe.demo.com" | |
Subject = "Items still containing tokens report" | |
Body = "Good afternoon,<br/>Please see the attached report for content items still containing tokens.<br/><br/>Guy with Glasses" | |
BodyAsHtml = $true | |
Attachments = $reportFile | |
SmtpServer = "localhost" | |
} | |
Send-MailMessage @email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment