Sitecore PowerShell Extensions
  • Introduction
  • Disclaimer
  • Installation
    • Contributor Guide
  • Training
  • Community
  • Interfaces
    • Console
    • Scripting
    • Interface Configuration
    • Interactive Dialogs
    • Help
  • Working with Items
    • Item Languages
    • Item Renderings
    • Variables
    • Providers
  • Modules
    • Libraries and Scripts
    • Integration Points
      • Content Editor
      • Control Panel
      • Data Sources
      • Event Handlers
      • Functions
      • ISE Plugins
      • Page Editor
      • Pipelines
      • Reports
        • Authoring Reports
      • Tasks
        • Authoring Tasks
      • Toolbox
      • Web API
      • Workflows
    • Packaging
  • Remoting
  • Security
    • Users and Roles
  • Releases
  • Troubleshooting
  • Code Snippets
    • Item Links
    • Field Types
    • Manage Templates
  • Appendix
    • Common
      • Add-BaseTemplate
      • Add-ItemVersion
      • Close-Window
      • ConvertFrom-CliXml
      • ConvertFrom-ItemClone
      • ConvertTo-CliXml
      • Expand-Token
      • Get-Archive
      • Get-ArchiveItem
      • Get-Cache
      • Get-Database
      • Get-ItemClone
      • Get-ItemCloneNotification
      • Get-ItemField
      • Get-ItemReference
      • Get-ItemReferrer
      • Get-ItemTemplate
      • Get-ItemWorkflowEvent
      • Get-SitecoreJob
      • Get-SpeModule
      • Get-SpeModuleFeatureRoot
      • Get-TaskSchedule
      • Get-UserAgent
      • Import-Function
      • Invoke-JavaScript
      • Invoke-Script
      • Invoke-ShellCommand
      • Invoke-Workflow
      • New-ItemClone
      • New-ItemWorkflowEvent
      • New-UsingBlock
      • Out-Download
      • Publish-Item
      • Read-Variable
      • Receive-File
      • Receive-ItemCloneNotification
      • Remove-BaseTemplate
      • Remove-ArchiveItem
      • Remove-ItemVersion
      • Reset-ItemField
      • Restart-Application
      • Restore-ArchiveItem
      • Send-File
      • Send-SheerMessage
      • Set-HostProperty
      • Set-ItemTemplate
      • Show-Alert
      • Show-Application
      • Show-Confirm
      • Show-FieldEditor
      • Show-Input
      • Show-ListView
      • Show-ModalDialog
      • Show-Result
      • Show-YesNoCancel
      • Start-TaskSchedule
      • Test-BaseTemplate
      • Test-Rule
      • Update-ItemReferrer
      • Update-ListView
      • Write-Log
    • Indexing
      • Find-Item
      • Get-SearchIndex
      • Initialize-Item
      • Initialize-SearchIndex
      • Initialize-SearchIndexItem
      • Remove-SearchIndexItem
      • Resume-SearchIndex
      • Stop-SearchIndex
      • Suspend-SearchIndex
    • Packaging
      • Export-Item
      • Export-Package
      • Export-UpdatePackage
      • Get-Package
      • Get-Preset
      • Get-UpdatePackageDiff
      • Import-Item
      • Install-Package
      • Install-UpdatePackage
      • New-ExplicitFileSource
      • New-ExplicitItemSource
      • New-FileSource
      • New-ItemSource
      • New-SecuritySource
      • Import-Item
      • New-Package
    • Presentation
      • Add-PlaceholderSetting
      • Add-Rendering
      • Get-Layout
      • Get-LayoutDevice
      • Get-PlaceholderSetting
      • Get-Rendering
      • Get-RenderingParameter
      • Merge-Layout
      • New-PlaceholderSetting
      • New-Rendering
      • Remove-PlaceholderSetting
      • Remove-Rendering
      • Remove-RenderingParameter
      • Reset-Layout
      • Set-Layout
      • Set-Rendering
      • Set-RenderingParameter
      • Switch-Rendering
    • Provider
      • Get-Item
    • Security
      • Add-ItemAcl
      • Add-RoleMember
      • Clear-ItemAcl
      • Disable-User
      • Enable-User
      • Export-Role
      • Export-User
      • Get-Domain
      • Get-ItemAcl
      • Get-Role
      • Get-RoleMember
      • Get-User
      • Import-Role
      • Import-User
      • Lock-Item
      • Login-User
      • Logout-User
      • New-Domain
      • New-ItemAcl
      • New-Role
      • New-User
      • Protect-Item
      • Remove-Domain
      • Remove-Role
      • Remove-RoleMember
      • Remove-User
      • Set-ItemAcl
      • Set-User
      • Set-UserPassword
      • Test-Account
      • Test-ItemAcl
      • Unlock-Item
      • Unprotect-Item
      • Unlock-User
    • Session
      • Get-ScriptSession
      • Get-Session
      • Receive-ScriptSession
      • Remove-ScriptSession
      • Remove-Session
      • Start-ScriptSession
      • Stop-ScriptSession
      • Wait-ScriptSession
Powered by GitBook
On this page
  • Package Creation
  • Post Step
Export as PDF
  1. Modules

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.

$package = New-Package "Package-of-Stuff"
$package.Sources.Clear()

$package.Metadata.Author = "Michael West"
$package.Metadata.Publisher = "Team Awesome"
$package.Metadata.Version = "1.0"
$package.Metadata.Readme = @"
Set of instructions for the user.
"@

# Items using New-ItemSource and New-ExplicitItemSource
$source = Get-Item -Path "master:\templates\Feature\Forms" | 
    New-ItemSource -Name 'Feature Forms Items' -InstallMode Overwrite
$package.Sources.Add($source)

# Files using New-FileSource and New-ExplicitFileSource
$source = Get-Item -Path "$AppPath\App_Config\Include\Feature\Forms\Company.Feature.Forms.config" | 
    New-ExplicitFileSource -Name "Feature Forms Files"
$package.Sources.Add($source)

Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).xml"
Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).zip" -Zip
Download-File "$SitecorePackageFolder\$($package.Name)-$($package.Metadata.Version).zip"

Post Step

Example: The following adds a Post Step and custom attributes.

$package = New-Package "Package-of-Stuff"
$package.Sources.Clear()

$package.Metadata.Author = "Michael West"
$package.Metadata.Publisher = "Team Awesome"
$package.Metadata.Version = "1.0"
$package.Metadata.Readme = @"
Set of instructions for the user.
"@
$package.Metadata.PostStep = "Some.Library.Class,Some.Library"
$package.Metadata.Attributes = "scriptId={9b9a3906-1979-11e7-8c9d-177c30471cec}|width=50|height=200"

Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).xml"

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.

Import-Function -Name New-PackagePostStep

$package = New-Package "Package-of-Stuff"
$package.Sources.Clear()

$package.Metadata.Author = "Michael West"
$package.Metadata.Publisher = "Team Awesome"
$package.Metadata.Version = "1.0"
$package.Metadata.Readme = @"
Set of instructions for the user.
"@
$newPackageFiles = @([PSCustomObject]@{"FileName"="/bin/Company.Feature.Unused.dll"})
$package.Metadata.PostStep = "Spe.Package.Install.PackagePostStep, Spe.Package"
$package.Metadata.Comment = New-PackagePostStep -PackageFiles $newPackageFiles

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.

$package = New-Package "Package-of-Stuff"
$package.Sources.Clear()

$package.Metadata.Author = "Michael West"
$package.Metadata.Publisher = "Team Awesome"
$package.Metadata.Version = "1.0"
$package.Metadata.Readme = @"
Set of instructions for the user.
"@
$package.Metadata.PostStep = "Spe.Integrations.Install.ScriptPostStep, Spe"
$package.Metadata.Attributes = "scriptId={737CD0CC-12F7-4528-8FBD-E0FDEFC41325}"
Write-Log "Processing changes to ensure backwards compatibility."
$oldVersion = New-Object System.Version(10,0)
if($PSVersionTable["SitecoreVersion"] -lt $oldVersion) {
    $iseButton = Get-Item -Path "core:{bfc79034-857c-4432-a5c2-2d93af784384}"
    $iseButton.Editing.BeginEdit()
    $iseButton.Fields["{D25B56D4-23B6-4462-BE25-B6A6D7F38E13}"].Value = "powershell/32x32/ise8.png"
    $iseButton.Editing.EndEdit() > $null

    $reportButton = Get-Item -Path "core:{74744022-353c-43f1-b8e4-5bc569ca9348}"
    $reportButton.Editing.BeginEdit()
    $reportButton.Fields["{D25B56D4-23B6-4462-BE25-B6A6D7F38E13}"].Value = "Office/32x32/chart_donut.png"
    $reportButton.Editing.EndEdit() > $null
    Write-Log "Changes complete."
} else {
    Write-Host "No changes required."
}
Close-Window
PreviousWorkflowsNextRemoting

Last updated 2 years ago