Last active
September 10, 2015 13:31
-
-
Save Dalmirog-zz/80dd112b0a798603ab7f to your computer and use it in GitHub Desktop.
Remove Library variable set references from all projects
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
| #Config | |
| $OctopusAPIKey = "" | |
| $OctopusURL = "" | |
| $header = @{ "X-Octopus-ApiKey" = $OctopusAPIKey } | |
| #Library Variable Set (LVS) to remove from projects | |
| $LibraryVariableSetIDs = ("LibraryVariableSets-1","LibraryVariableSets-2") | |
| #Getting all the projects on the Octopus instance | |
| $AllProjects = Invoke-WebRequest "$OctopusURL/api/projects/all" -Headers $header | select -ExpandProperty Content | ConvertFrom-Json | |
| #Getting the projects that are using the deleted LVS | |
| $ProjectsToUpdate = $AllProjects | ?{$_.IncludedLibraryVariableSetIds -contains $LibraryVariableSetID} | |
| #Printing projects to update | |
| $ProjectsToUpdate.Name | |
| #Loop to fix projects | |
| foreach ($project in $ProjectsToUpdate){ | |
| Try{ | |
| Write-output "Updating project $($project.Name)" | |
| #Removing all LVS from the project | |
| [System.Collections.ArrayList]$ids = $Project.IncludedLibraryVariableSetIds | |
| foreach($LibraryVariableSetID in $LibraryVariableSetIDs){ | |
| if($LibraryVariableSetID -in $ids){ | |
| $ids.Remove($LibraryVariableSetID) | |
| } | |
| } | |
| #$ids.Remove($LibraryVariableSetID) | |
| $project.IncludedLibraryVariableSetIds = $ids | |
| #Saving changes on server | |
| Invoke-WebRequest "$OctopusURL/api/projects/$($Project.id)" -Method PUT -Headers $header -Body ($project | ConvertTo-Json -Depth 4) | |
| } | |
| Catch{ | |
| $_ | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment