Enable and Disable Publishing Targets with SPE

pexels-pixabay-416760 (3)

It’s been a while since my last post as back February & March I was preparing for presenting at the Swiss Sitecore user group and I’ve been pretty busy since then, So I thought it’s time I shared some things that other might find useful from the past few months.

The client I’m currently working with needs to Toggle On and Off publishing Targets quite often in their UAT environment during performance testing.  I posted a question a while ago on SPE about how I could do this but the answers about setting permissions for specific users were not really feasible for me.

So I wrote an SPE script to delete and restore the Publishing Targets, however  our version of SPE (5.1) was too old for it to work (as I’m using the Restore-ArchiveItem function). We recently upgraded to SPE 6.2 and I was able to test it and it works great.

The Function

We have a Web and Pub publishing Targets so you will need to update these and the ids in the function below:

 

How to use It

Import the above function and then pass either ‘on’ or ‘off’ to it.

Import-Function Toggle-Publishing-Targets

Toggle-Publishing-Targets -state “on”

Thats it. You’ll get some feedback in the console to inform you when it’s removing them or restoring them.

It takes about 20 seconds or so to run in our UAT environment for some reason but it’s a nice quick way of doing this when needed. Hopefully this is useful for others too.