2 Updated the Tags
| link
source | link

SPE How to add multiple items to package source

I'm writing a SPE script to package up all unused media library items under a specific folder (prior to deletion). I've found New-Package and New-ItemSource methods and know how to use them (to some extent). How can I add multiple items from a collection to a single ItemSource object?

My script so far looks like this:

$items = Get-ChildItem -Path "master:\sitecore\media library\Project\ACME" -Recurse | 
Where-Object { $_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder} |
Where-Object { ![Sitecore.Globals]::LinkDatabase.GetReferrerCount($_) -gt 0}

# Create package
$package = new-package "Unused Media Items";

# Set package metadata
$package.Metadata.Author = "ACME";
$package.Metadata.Publisher = "ACME";
$package.Metadata.Version = "1.0.0";
$package.Metadata.Readme = "";

$source = $items | New-ItemSource -Name 'Media' -InstallMode Overwrite

It seems that when I pipe a collection object to New-ItemSource it only picks up the last item. It seems wrong to create a new itemsource object for each item, but maybe that is not an issue?