Doing this via Sitecore Powershell will be a tedious task. One possible solution is to hook into the packageinstall:items:ended
event.
This event will allow you to retrieve all the ItemUri, hence you will have the item ids. Below is the code snippet on how to implement the event listener.
Code Snippet
public class ItemPackageEvent
{
public void OnPackageInstallItemsEndHandler(object sender, EventArgs e)
{
if (e == null)
{
return;
}
SitecoreEventArgs sitecoreEventArgs = e as SitecoreEventArgs;
if (sitecoreEventArgs == null || sitecoreEventArgs.Parameters == null || sitecoreEventArgs.Parameters.Length != 1)
{
return;
}
InstallationEventArgs parameter = sitecoreEventArgs.Parameters[0] as InstallationEventArgs;
// The paramter.ItemsToInstall provides the list of items together with the item id, language that have been installed on the CMS
// Check for null in case no item is available.
if (parameter == null || parameter.ItemsToInstall == null)
{
return;
}
// Implement here your code for the publishing.
}
}
Config File Patch
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:role="http://www.sitecore.net/xmlconfig/role/" xmlns:search="http://www.sitecore.net/xmlconfig/search/">
<sitecore>
<events>
<event name="packageinstall:items:ended">
<handler type="YourNamespace.ItemPackageEvent, YourAssemblyName" method="OnPackageInstallItemsEndHandler" />
</event>
</events>
</sitecore>
</configuration>
Note that if ever you have already implemented your SPE script to trigger the publish, you can still use it in the code. All you need to do is to call the Powershell Script.
More information on how to call the Powershell Script via code can be found at the following StackOverflow question.