Normally, something this light wouldn’t be a blog post, but here we are.
If you’ve used PowerShell to publish content before, maybe some import process or third party integration into the CMS…you know it’s pretty straight forward:
Publish-Item -Path master:\content\home -Target Internet
That’s not hard. Now instead of a normal DB Target, you want to publish to Experience Edge. Same dealio, right? If the answer was yes, you and I wouldn’t be here. We’d be sippin on the shore. Here’s what happens when you change to publish to Edge:
Ok…so something is up here. I tried swapping this to “web” to see if my syntax was off. It was not (gold star for me!). Something must be special about the Edge target… I dug around in the SPE assemblies a bit, and couldn’t find anything valuable, so I hopped on slack and bugged my favorite friends. We did some team debugging and decided that we could try to work around this by just going straight to the PublishManager that SPE and the Publish Dialog both wrap. In its simplest static incantation, it takes a handful of easy-to-get parameters, and runs as a singleton (yay). Check it out:
We can get the item, and databases pretty easily. And bools are just bools. The language on the other hand, isn’t something that’s as easily ascertained (as a Language Object vs an Item). We can dig a little into the Language class though, and see there’s a Parse method:
When you put that all together, you get something like this:
$pItem = Get-Item -Path "master:/sitecore/media library/Project/Tenant/Client/Sitemaps/sitemap"
$db = Get-Database "experienceedge"
$lang = [Sitecore.Globalization.Language]::Parse("en")
[Sitecore.Publishing.PublishManager]::PublishItem($pItem, $db, $lang, $false, $false)
Once you run that, you can check your jobs.aspx to see that it has, in fact, kicked off a publish. Yay! PowerShell and assembly de-compilation is there a more iconic duo? Yes. Yes there is.
For what it’s worth, I did file a bug on the the ol’ GitHub: https://github.com/SitecorePowerShell/Console/issues/1314. According to the team, it should be fixed in a future version. Until then, the above code should satisfy all your fancy edge publishing needs!