Last active
September 2, 2015 15:39
-
-
Save Dalmirog-zz/a9a84bc260f40aa445d7 to your computer and use it in GitHub Desktop.
Examples of updating machine roles using Octoposh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 1) Updating a Machine's roles | |
| #getting the machine | |
| $machine = Get-OctopusMachine -MachineName "MyMachine" | |
| #updating the machine's roles | |
| $machine.resource.roles.add("NewRoleToAdd") | |
| $machine.resource.roles.Remove("OldRoleToRemove") | |
| #Saving the machine resource on the database | |
| Update-OctopusResource -Resource $machine.resource | |
| ## 2) Updating the roles of a group of machines | |
| #Getting all the machines inside of an Environment | |
| $EnvMachines = Get-OctopusMachine -EnvironmentName Development | |
| #Looping through all the machines and changing their roles | |
| foreach ($machine in $EnvMachines){ | |
| $machine.resource.roles.add("NewRoleToAdd") #adding a role | |
| $machine.resource.roles.Remove("OldRoleToRemove") #removing a role | |
| } | |
| #updating all machines at once | |
| Update-OctopusResource -Resource $EnvMachines.resource -Force |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment