Created
August 22, 2016 12:57
-
-
Save KennethBates/1bce8ee8a9da43c0cc6bdacd71bc4b0d to your computer and use it in GitHub Desktop.
Add Variable Sets to all projects
This file contains 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
$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