【问题标题】:Is there a way to bypass the Power-Shell confirmation(Y/N) prompt in Azure Automation Runbook有没有办法绕过 Azure 自动化运行手册中的 Powershell 确认(Y/N)提示
【发布时间】:2020-12-20 20:15:32
【问题描述】:

有没有办法绕过 Azure Automation Runbook 中 PowerShell cmdlet 的确认提示(是/否)。

使用 ECHO Y | powershell 在本地运行良好,但在 Azure 自动化中不行。

以下是错误

“PowerShell”一词未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,如果包含路径,请验证路径是否正确,然后重试。

也尝试使用ECHO Y | pwsh

任何建议或意见将不胜感激。

# 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 $_ "
        
    }

}

【问题讨论】:

    标签: azure-automation


    【解决方案1】:

    一般来说,您可以通过here 解释的各种方式绕过确认。如果您分享更多关于您的 Runbook 尝试完成的内容的背景信息,则可以推荐最简单、最安全的方法。

    更新 2: 感谢您提供有关该问题的更多背景信息。由于该问题与 AzSK 有关,默认情况下不接受上述 -Confirm / -Force 等,因此我向 AzSK 的维护者提出了this 功能请求。请检查它以了解未来的更新。

    另外,请查看 khushboo 在this 问题中的回复,该问题解释了相关问题。

    【讨论】:

    • 我们正在使用 AzSK PowerShell 模块来检查 Azure 资源的安全性。 Link 该作业每三个小时运行一次,并提供安全报告。如果存在安全漏洞(例如:Web 应用程序未启用 AlwaysOn)我们需要手动修复该事物,或者我们需要使用“WillFixLater,NotAnIssue”来证明资源。对于证明,我们正在考虑使用 azure 自动化运行手册。但问题是,认证启动时会提示用户使用“是/否”选项继续认证。
    • 我可以通过在本地使用 ECHO Y | PowerShell 绕过这个 Yes/No 提示。但它不适用于 azure 自动化运行手册。
    • 仅供参考,该模块没有强制/确认开关。
    • 用运行手册代码更新了初始询问,供您参考
    • 感谢分享运行手册。使用更新 2 部分下的附加信息更新了上述答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 2019-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-01-18
    相关资源
    最近更新 更多