Packaging
Ever wanted to package up items and files without opening the Sitecore Package Designer each time? There are a number of commands available for generating packages.

Package Creation

Example: The following example demonstrates how to generate a package.
1
$package = New-Package "Package-of-Stuff"
2
$package.Sources.Clear()
3
4
$package.Metadata.Author = "Michael West"
5
$package.Metadata.Publisher = "Team Awesome"
6
$package.Metadata.Version = "1.0"
7
$package.Metadata.Readme = @"
8
Set of instructions for the user.
9
"@
10
11
# Items using New-ItemSource and New-ExplicitItemSource
12
$source = Get-Item -Path "master:\templates\Feature\Forms" |
13
New-ItemSource -Name 'Feature Forms Items' -InstallMode Overwrite
14
$package.Sources.Add($source)
15
16
# Files using New-FileSource and New-ExplicitFileSource
17
$source = Get-Item -Path "$AppPath\App_Config\Include\Feature\Forms\Company.Feature.Forms.config" |
18
New-ExplicitFileSource -Name "Feature Forms Files"
19
$package.Sources.Add($source)
20
21
Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).xml"
22
Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).zip" -Zip
23
Download-File "$SitecorePackageFolder\$($package.Name)-$($package.Metadata.Version).zip"
Copied!

Post Step

Example: The following adds a Post Step and custom attributes.
1
$package = New-Package "Package-of-Stuff"
2
$package.Sources.Clear()
3
4
$package.Metadata.Author = "Michael West"
5
$package.Metadata.Publisher = "Team Awesome"
6
$package.Metadata.Version = "1.0"
7
$package.Metadata.Readme = @"
8
Set of instructions for the user.
9
"@
10
$package.Metadata.PostStep = "Some.Library.Class,Some.Library"
11
$package.Metadata.Attributes = "scriptId={9b9a3906-1979-11e7-8c9d-177c30471cec}|width=50|height=200"
12
13
Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).xml"
Copied!
Example: The following adds a Post Step included with SPE to delete a file. The SPE Post Step code reads xml data stored in the comment section of the package.
1
Import-Function -Name New-PackagePostStep
2
3
$package = New-Package "Package-of-Stuff"
4
$package.Sources.Clear()
5
6
$package.Metadata.Author = "Michael West"
7
$package.Metadata.Publisher = "Team Awesome"
8
$package.Metadata.Version = "1.0"
9
$package.Metadata.Readme = @"
10
Set of instructions for the user.
11
"@
12
$newPackageFiles = @([PSCustomObject]@{"FileName"="/bin/Company.Feature.Unused.dll"})
13
$package.Metadata.PostStep = "Spe.Package.Install.PackagePostStep, Spe.Package"
14
$package.Metadata.Comment = New-PackagePostStep -PackageFiles $newPackageFiles
Copied!
Example: The following adds a Post Step Script included with SPE to change icons. The SPE Post Step code executes a script included with the package as stored in the attributes section.
1
$package = New-Package "Package-of-Stuff"
2
$package.Sources.Clear()
3
4
$package.Metadata.Author = "Michael West"
5
$package.Metadata.Publisher = "Team Awesome"
6
$package.Metadata.Version = "1.0"
7
$package.Metadata.Readme = @"
8
Set of instructions for the user.
9
"@
10
$package.Metadata.PostStep = "Spe.Integrations.Install.ScriptPostStep, Spe"
11
$package.Metadata.Attributes = "scriptId={737CD0CC-12F7-4528-8FBD-E0FDEFC41325}"
Copied!
1
Write-Log "Processing changes to ensure backwards compatibility."
2
$oldVersion = New-Object System.Version(10,0)
3
if($PSVersionTable["SitecoreVersion"] -lt $oldVersion) {
4
$iseButton = Get-Item -Path "core:{bfc79034-857c-4432-a5c2-2d93af784384}"
5
$iseButton.Editing.BeginEdit()
6
$iseButton.Fields["{D25B56D4-23B6-4462-BE25-B6A6D7F38E13}"].Value = "powershell/32x32/ise8.png"
7
$iseButton.Editing.EndEdit() > $null
8
9
$reportButton = Get-Item -Path "core:{74744022-353c-43f1-b8e4-5bc569ca9348}"
10
$reportButton.Editing.BeginEdit()
11
$reportButton.Fields["{D25B56D4-23B6-4462-BE25-B6A6D7F38E13}"].Value = "Office/32x32/chart_donut.png"
12
$reportButton.Editing.EndEdit() > $null
13
Write-Log "Changes complete."
14
} else {
15
Write-Host "No changes required."
16
}
17
Close-Window
Copied!
Last modified 10d ago
Export as PDF
Copy link