Created
August 26, 2015 21:09
-
-
Save Dalmirog-zz/9167bd9ca7617088623a to your computer and use it in GitHub Desktop.
Removes specific Variable Sets or Script modules from all/some projects in Octopus. Octoposh Module is required
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
| Import-Module Octoposh #You can get Octoposh from http://dalmirog.github.io/OctoPosh | |
| $VariableSetName = "" #variable set NAME, not ID | |
| $ScriptModuleName = "Test" #Script module NAME, not ID | |
| $ProjectList = ""#leave empty if you want to check all the project in your Octopus instance. Else add names between double quotes separated by a comma | |
| $VariableSet = Get-OctopusVariableSet -LibrarySetName $VariableSetName -ResourceOnly | |
| $ScriptModule = Get-OctopusVariableSet -LibrarySetName $ScriptModuleName -ResourceOnly | |
| $c = New-OctopusConnection | |
| If([string]::IsNullOrEmpty($ProjectList)){ | |
| $projects = Get-OctopusProject -ResourceOnly | |
| } | |
| else{ | |
| $projects = Get-OctopusProject -ProjectName $ProjectList -ResourceOnly | |
| } | |
| Foreach($project in $projects){ | |
| $update = $false | |
| Write-Output "Checking project: [$($project.name)]" | |
| If($project.IncludedLibraryVariableSetIds.Contains($VariableSet.OwnerId)){ | |
| Write-Output "--Project [$($project.name)] contains Variable Set [$VariableSetName]. Removing it..." | |
| If($project.IncludedLibraryVariableSetIds.Remove($VariableSet.OwnerId)){ | |
| $update = $true | |
| } | |
| } | |
| else{ | |
| Write-Output "--Project [$($project.name)] does not contain Variable Set [$VariableSetName]." | |
| } | |
| if($project.IncludedLibraryVariableSetIds.Contains($ScriptModule.OwnerId)){ | |
| Write-Output "--Project [$($project.name)] contains ScriptModule [$ScriptModuleName]. Removing it..." | |
| If($project.IncludedLibraryVariableSetIds.Remove($ScriptModule.OwnerId)){ | |
| $update = $true | |
| } | |
| } | |
| else{ | |
| Write-Output "--Project [$($project.name)] does not contain the Script Module [$ScriptModuleName]." | |
| } | |
| If ($update -eq $true){ | |
| Write-Output "--Saving changes on Project [$($project.name)]" | |
| If(Update-OctopusResource -Resource $project -Force){ | |
| Write-Output "--Changes on Project [$($project.name)] saved to the database" | |
| } | |
| else{ | |
| write-output "--Something went wrong saving project [$($project.name)]. Please try to make the changes manually from the web UI" | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment