Skip to content

Instantly share code, notes, and snippets.

@KennethBates
Created August 22, 2016 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KennethBates/1bce8ee8a9da43c0cc6bdacd71bc4b0d to your computer and use it in GitHub Desktop.
Save KennethBates/1bce8ee8a9da43c0cc6bdacd71bc4b0d to your computer and use it in GitHub Desktop.
Add Variable Sets to all projects
$OctopusAPIkey = "" #Octopus API Key to authenticate
$OctopusURL = "" #Octopus Server URL
$variableSetId = "" #Variable Set Id you want to add to projects
#Register the Octopus client and Newtonsoft JSON dlls for all this to work
Add-Type -Path "C:\Program Files\Octopus Deploy\Octopus\Newtonsoft.Json.dll"
Add-Type -Path "C:\Program Files\Octopus Deploy\Octopus\Octopus.Client.dll"
#Create a connection to the Octopus server using the URL and the API Key
$endpoint = new-object Octopus.Client.OctopusServerEndpoint "$($OctopusURL)","$($OctopusAPIKey)"
$repository = new-object Octopus.Client.OctopusRepository $endpoint
#Getting all projects
$allProjects = $repository.projects.findAll()
foreach($project in $allProjects) {
#Add the variable set to the project using the ID
$project.IncludedLibraryVariableSetIds.Add($variableSetId)
#Save the changes to the project on the database
$repository.Projects.Modify($project)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment