If you like to add the referenced items into your package using PowerShell
then you need to use Get-ItemReference
to get all the referenced items of the item that you want to include in your package. And then you need to loop through all the items to put them into your package and then the package will be created with the referenced items that you need. So the code should be something like this.
# Pass your item ID
$items = Get-ItemReference -ID "{56305117-8C9C-4C08-96D5-BB97A8E27419}"
$package = New-Package "Sitecore Package";
# Set package metadata
$package.Sources.Clear();
$package.Metadata.Author = "Sumit";
$package.Metadata.Publisher = "Sumit";
$package.Metadata.Version = "1.0";
$package.Metadata.Readme = 'Readme Text'
# Loop on all the related items and add into the package
ForEach ($item in $items) {
$source = $item | New-ExplicitItemSource -Name 'Your Page Name' -InstallMode Overwrite
$package.Sources.Add($source);
}
# Save package
Export-Package -Project $package -Path "$($package.Name)-$($package.Metadata.Version).zip" -Zip
# Offer the user to download the package
Download-File "$SitecorePackageFolder\$($package.Name)-$($package.Metadata.Version).zip"
Hope this will help.
Some useful links.
How to create a package.
https://doc.sitecorepowershell.com/appendix/packaging/new-package
Get item references.
https://doc.sitecorepowershell.com/appendix/common/get-itemreference
Get Item Renderings
https://doc.sitecorepowershell.com/working-with-items/item-renderings