Skip to main content

create a content package

This PS script will grab a list of Sitecore items by path and will create and download a content package in zip format.

$package = New-Package "TicketNumber_Description";
$readme = "TicketNumber and some info on what's being installed";

# Set package metadata
$package.Sources.Clear();
$package.Metadata.Author = "Dwaine Harding";
$package.Metadata.Publisher = "mycompany.com";
$package.Metadata.Version = "1.0";
$package.Metadata.Readme = $readme;

# List of item paths to add to package
$itemPaths = (
"master:/sitecore/path/to/item/1",
"master:/sitecore/path/to/item/2"
)

# Iterate over the items and add to package
foreach($itemPath in $itemPaths)
{
$source = Get-Item $itemPath | New-ItemSource -Name $.Name -InstallMode Overwrite
$package.Sources.Add($source);
}

# Save package
Export-Package -Project $package -Path "$($package.Name).zip" -Zip

# Offer the user to download the package
Download-File "$SitecorePackageFolder\$($package.Name).zip"
note

The New-ItemSource method will add the item provided as well as it's subitems as per docs