Last active
December 13, 2019 22:35
-
-
Save holtsoftware/da51a2fd555f987e7ec68bcc9ff4f551 to your computer and use it in GitHub Desktop.
Script to sync unicorn configs based on dependencies
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
[System.Collections.ArrayList]$configs = Get-UnicornConfiguration | |
[System.Collections.ArrayList]$synced = @() | |
[System.Collections.ArrayList]$toRemove = @() | |
$totalCount=0 | |
while($configs.Length -gt 0) | |
{ | |
$totalCount++ | |
if($totalCount -gt 100) | |
{ | |
break | |
} | |
foreach($c in $configs) | |
{ | |
if($c.Dependencies.Length -eq 0) | |
{ | |
Write-Host "No Dependencies in $($c.Name)" | |
$c | Sync-UnicornConfiguration | |
$toRemove.Add($c); | |
$synced.Add($c.Name); | |
} | |
else | |
{ | |
$countSynced = 0 | |
foreach($d in $c.Dependencies) | |
{ | |
if($synced.Contains($d)) | |
{ | |
$countSynced++ | |
} | |
} | |
if($c.Dependencies.Length -eq $countSynced) | |
{ | |
Write-Host "Dependencies Synced. Syncing in $($c.Name)" | |
$c | Sync-UnicornConfiguration | |
$toRemove.Add($c); | |
$synced.Add($c.Name); | |
} | |
} | |
} | |
foreach($r in $toRemove) | |
{ | |
$configs.Remove($r) | |
} | |
$toRemove.Clear() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment