The Sitecore PowerShell Extensions is a very powerful module what allows you to automate a lot of the trivial Sitecore tasks.
The Export-Package command will create a Sitecore package. This script will read a list of Sitecore item paths from a list, and add these to a package, then the package is downloaded.
The script was given to me by my colleague Adam Honoré, who should be credited.
$ItemsToBeDeployed = @( @{ Recursive = $TRUE; Source = "master:/content/.../.../..." }, @{ Recursive = $FALSE; Source = "core:/content/.../.../..." }, ... ... ); $ErrorActionPreference = "Stop" $Package = New-Package -Name "My Package"; $Package.Sources.Clear(); $Package.Metadata.Author = "PowerShell"; $Package.Metadata.Publisher = "Pentia"; $Package.Metadata.Version = Get-Date -Format FileDateTimeUniversal; $Package.Metadata.Readme = 'This will install a Sitecore Package generated using PowerShell' ForEach ($Item in $ItemsToBeDeployed) { if ($Item.Recursive) { $Source = Get-Item $Item.Source | New-ItemSource -Name "N/A" -InstallMode Overwrite $Package.Sources.Add($Source); } else { $Source = Get-Item $Item.Source | New-ExplicitItemSource -Name "N/A" -InstallMode Overwrite $Package.Sources.Add($Source); } } # Save and Download Package Export-Package -Project $package -Path "$( $package.Name ) - $( $package.Metadata.Version ).zip" -Zip Download-File "$SitecorePackageFolder\$( $package.Name ) - $( $package.Metadata.Version ).zip"
HOW IT WORKS:
The $ItemsToBeDeployed variable contains a list of all the root items to be included in the package. Use the “Recursive” property to determine whether to include only the root item, or to include all children as well. Prefix the item path with the name of the database to get the item from.
The $Package variable is the package itself. You can set the various package properties here. The script will iterate through the $ItemsToBeDeployed variable, adding each item on the list as package sources.
Finally, the Export-Package powershell command is called to create the package, and the Download-File method is called to get the package from Sitecore.
MORE TO READ:
- Export-Package Sitecore PowerShell extension from doc.sitecorepowershell.com
- Send-File PowerShell extension from doc.sitecorepowershell.com
- Sitecore PowerShell GitHub repo
- Guide to Sitecore Packaging by Sean Holmesby