Export/Import Target Roles

(Jonathan Jenkins) #1

Hello. I am new to Octopus and have searched online for an answer to my question with no success. I have a multiple Deployment Targets that each have around 45 Target Roles. I have been asked to add these Target Roles to 5 different Deployment Targets. So I basically have to manually copy 40+ Target Roles from 1 Deployment Target to another. Then do this another 4 times. Each Deployment Target has different Target Roles as well. Is there a scripted approach I could take that could export the Target Roles to a report and then import then to a different Deployment Target? I have been checking different Powershell options and API calls and have found nothing. It seems like it would be a common request.

Thanks all.

(Kenneth Bates) #3

Hi Jonathan,

Thanks for getting in touch! Welcome to Octopus, and I hope you’ve found it useful so far. :slight_smile:

That certainly would be tedious to have to add 45 roles manually to multiple targets, and I’m surprised as well that I can’t seem to find a script to this specific task. The closest sample script I’ve found is to add a single role (which you specify in the script) to a target, which I’ll paste a link to below. You can add multiple by comma-separating the entries, i.e. line 10 could look like $machine.roles += ("Role1", "Role2", "Role3").

To get the roles already existing on another machine, you could do a GET on the machine, or you could use the system variable Octopus.Machine.Roles to get a list of roles assigned to the machine and then plug the results into the AddRoleToTarget.ps1 script.

I hope this helps! Let me know how you go or if you have any further questions going forward. :slight_smile:

Best regards,


(Jonathan Jenkins) #4

Thank you for the response Kenny. I am going to play around with this today and see where it takes me. It should be fun. Your info is very helpful. I’ll eventually reply with my results.

Thanks again.

(Kenneth Bates) #5

Hi Jonathan,

You’re quite welcome, and thanks for keeping in touch! Don’t hesitate to reach out if you have any followup questions or concerns moving forward. :slight_smile:

Best regards,


(system) closed #6

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.