Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Last active September 2, 2015 15:39
Show Gist options
  • Select an option

  • Save Dalmirog-zz/a9a84bc260f40aa445d7 to your computer and use it in GitHub Desktop.

Select an option

Save Dalmirog-zz/a9a84bc260f40aa445d7 to your computer and use it in GitHub Desktop.
Examples of updating machine roles using Octoposh
## 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