Skip to content

Instantly share code, notes, and snippets.

@AdamNaj
AdamNaj / LiveProgressTest.ps1
Created August 3, 2015 11:38
Live Update test
gci master:\ -rec
$colors = "Cyan", "Gray","Green","Magenta","Red","White","Yellow"
foreach($i in 1..20){
foreach($j in 1..20){
Write-Host ("{0:D3} " -f ($i*20+$j)) -ForegroundColor "$($colors[(Get-Random -Maximum $colors.Length)])" -no
Write-Progress -Activity "Line $i, column $j" -PercentComplete (($i*20+$j)/4.2)
Start-Sleep -Milliseconds 10
}
@AdamNaj
AdamNaj / Retrieve-SitecorePackage (failed).ps1
Last active August 29, 2015 14:27
File Download attempt
# unfortunately does not work, because - #1 - does not really retrieve the file, #2 has problems with logging out
Import-Module -Name SPE
function Retrieve-SitecorePackage($session, $instance, $PackageName, $Destination){
$loginUri = "$instance/sitecore/login"
$login = Invoke-WebRequest -Uri $loginUri -SessionVariable webSession
$form = $login.Forms[0]
$form.Fields["__EVENTTARGET"] = ""
$form.Fields["UserName"] = $session.Username
Import-Module -Name SPE
function Retrieve-SitecorePackage($session, $instance, $PackageName, $Destination){
Invoke-WebRequest "$instance/-/script/file/package/?path=$PackageName&user=$($session.Username)&password=$($session.Password)" -OutFile $Destination -WebSession $webSession
}
$instance = "http://sitecore8"
$session = New-ScriptSession -Username admin -Password b -ConnectionUri $instance
$packageName = "package.zip"
@AdamNaj
AdamNaj / Get-SitecoreLogTail.ps1
Created September 4, 2015 18:55
Get last 10 lines of the latest sitecore blog.
Get-ChildItem "$($SitecoreLogFolder)\log*.*" | Sort-Object -Descending LastWriteTime | Select-Object -First 1 | Get-Content -Tail 10
@AdamNaj
AdamNaj / Receive-Zip.ps1
Created September 15, 2015 20:12
Upload and Unzip dialog
# replace "target folder" with the path in the media library you want to put your files in.
Receive-File -ParentItem (gi "master:\media library\target folder") -AdvancedDialog
@AdamNaj
AdamNaj / New-MediaItem.ps1
Last active July 23, 2016 12:43
Create Media item from file on server drive
function New-MediaItem{
[CmdletBinding()]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[ValidateNotNullOrEmpty()]
[string]$filePath,
[Parameter(Position=1, Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]$mediaPath)
@AdamNaj
AdamNaj / Fix-ZGCars.ps1
Created September 27, 2015 03:29
Fix ZG Cars media
Get-childitem "master:/media library/Showcase-Group/search/int/images/cars" -rec |
? { $_."File Path" -ne $null } |
% { $_."File Path" = $_."File Path" -replace "/Replicated", "" }
@AdamNaj
AdamNaj / 00_Get-ItemsChangedInLast7Days.ps1
Last active February 24, 2016 16:24
SUGCON Presentation
$days = 7;
Get-ChildItem master:\content\home -Recurse |
? { $_."__updated" -gt (Get-Date).AddDays(-$days) } |
Format-Table -Property ID, Name, "__updated", "__updated by"
#This script will create sitecore items based on given count and template
$InputCount=10
$InputTemplate = Get-Item "master:\templates\Sample\Sample Item"
$result = Read-Variable `
-Parameters @{Name="InputCount"; Title="How many items do you want to create?"},
@{Name="InputTemplate"; Title="Using which template you want to create item?"; root="/sitecore/templates/"} `
-Title "Bulk item create tool" `
-Description "Please provide the number of items and the template that you want to be used"
if($result -eq "ok"){
@AdamNaj
AdamNaj / Set-ItemFieldToExternalLink.ps1
Created October 26, 2015 20:47
Set item field to external url