Skip to content

Commit 07e53ad

Browse files
committed
add logic for remove all runbooks that have different RuntimeEnvironment
1 parent 2c0f1eb commit 07e53ad

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Tasks/Manage-AutomationAccount/Manage-AutomationAccount.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,31 @@ if (Check-Scope -Scope $scope -RequiredScope 'Runbooks') {
585585
-Location $runbook.Location
586586
$importingRunbooks.Add($runbook) | Out-Null
587587
}
588+
589+
#--remove all runbooks that have different RuntimeEnvironment:
590+
#1. Get a list of currently installed runtimes:
591+
$installedRunbooks = Get-AutoObject -objectType Runbooks
592+
593+
#2.Comparing with importingRunbooks list and in case different RuntimeEnvironment then add to list for remove:
594+
$runbooksToRemoveDueDifferentEnvironment = @()
595+
foreach($installedRunbook in $installedRunbooks) {
596+
597+
$runbookToCheck = $importingRunbooks | Where-Object { $_.Name -in $installedRunbook.Name }
598+
if ($null -ne $runbookToCheck) {
599+
if ($runbookToCheck.RuntimeEnvironment -ne $installedRunbook.RuntimeEnvironment) {
600+
$runbooksToRemoveDueDifferentEnvironment.Add($runbookToCheck)
601+
}
602+
}
603+
}
604+
605+
foreach($runbook in $runbooksToRemoveDueDifferentEnvironment)
606+
{
607+
"Removing $($runbook.Name) for runtime $($runtimeEnvironment.Name) that is different to importing version."
608+
#TODO Remove-AutoObject -Name $runbook.Name -objectType Runbooks | Out-Null
609+
}
610+
611+
#--
612+
588613
#wait for runbook import completion
589614
if ($importingRunbooks.Count -gt 0) {
590615
'Waiting for import of runbooks'
@@ -596,8 +621,10 @@ if (Check-Scope -Scope $scope -RequiredScope 'Runbooks') {
596621
Write-Error "Some runbooks failed to import"
597622
}
598623
}
624+
599625
if ($fullSync) {
600626
$allRunbooks = Get-AutoObject -objectType Runbooks
627+
#if runbook from definition is not on server then delete:
601628
$runbooksToRemove = $allRunbooks | Where-Object { $_.Name -notin $definitions.Name }
602629
foreach($runbook in $runbooksToRemove)
603630
{

vss-extension.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifestVersion": 1,
33
"id": "Manage-AutomationAccount",
44
"name": "Manage-AutomationAccount",
5-
"version": "2.0.3",
5+
"version": "2.0.4",
66
"publisher": "GreyCorbelSolutions",
77
"targets": [
88
{

0 commit comments

Comments
 (0)