Home > OS >  Remove-AzAutomationSchedule needs confirmation, even with confirm parameter
Remove-AzAutomationSchedule needs confirmation, even with confirm parameter

Time:07-20

I got a code collecting and deleting expired azure automation schedules

Connect-AzAccount -SubscriptionId "guidstuff"
$schedules = Get-AzAutomationSchedule -ResourceGroupName "resgrp" -AutomationAccountName "automationacc" | ?{$_.name -like "schedule1*" -and $_.expirytime -lt (get-date)}
$cache = Get-AzAutomationSchedule -ResourceGroupName "resgrp" -AutomationAccountName "automationacc" | ?{$_.name -like "schedule2*" -and $_.expirytime -lt (get-date)}
if($cache.count -ne 0){
    $schedules  = $cache
}
foreach($schedule in $schedules){
    Remove-AzAutomationSchedule -Confirm:$false -AutomationAccountName $schedule.AutomationAccountName -ResourceGroupName $schedule.ResourceGroupName -Name $schedule.name 
}

Its asking deletion-confirmation for every schedule, am I or is the CMDlet wrong ?

CodePudding user response:

Its asking deletion-confirmation for every schedule, am I or is the CMDlet wrong ?

As suggested by @theo, we reproduced in our local environment by using the below cmdlet:

By default, -Confirm value is set to false only.

Remove-AzAutomationSchedule -AutomationAccountName 'tstautmation'-ResourceGroupName 'test-rg' -Name 'terer' -Confirm:$false -Force

Now, it will not ask for deletion-confirmation every time when we run the above command.

Refer this document for more information.

  • Related