1
votes

Is there a way to bypass the PowerShell cmdlet's confirmation prompt (Yes/No) in Azure Automation Runbook.

Using ECHO Y | powershell worked fine locally, but not in Azure Automation.

Below is the error

The term 'PowerShell' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Tried with the ECHO Y | pwsh as well.

Any suggestions or advice will be appreciated.

# Attestation
foreach ($inputItem in $inputContents) {
    
    $ControlID = $inputItem.ControlID
    $ResourceName = $inputItem.ResourceName
    $AttestationStatus = $inputItem.AttestationStatus
    $JustificationText = $inputItem.JustificationText

    try {
        echo Y | powershell Get-AzSKAzureServicesSecurityStatus -SubscriptionId $RunAsConnection.SubscriptionId `
            -ResourceNames $ResourceName `
            -ControlsToAttest NotAttested `
            -ControlId $ControlID `
            -AttestationStatus $AttestationStatus `
            -JustificationText $JustificationText

            Write-Host "INFO: Completed the attestation for $ResourceName"
    }
    catch {
        Write-Host "ERROR: Could not attest the resource $ResourceName due to error $_ "
        
    }

}
1

1 Answers

0
votes

In general, you can bypass the confirmation in various ways as explained here. The easiest and safest way can be recommended if you share more context on what your runbook is trying to accomplish.

UPDATE 2: Thanks for providing additional context around the issue. As the issue is related to AzSK which by default doesn't accept above mentioned -Confirm / -Force, etc. so I have raised this feature request with maintainers of the AzSK. Please check it for future updates on it.

Also, check response from khushboo in this question which explains regarding related issue.