Azure PowerShell Start-AzureAutomationRunbook未指定默认订阅

时间:2017-08-17 18:46:44

标签: powershell azure azure-devops azure-pipelines-build-task azure-automation

VSTS上的Azure PowerShell v2。*能够执行

if (isset($_POST['btn-submit'])){
    $firstName = trim($_POST['fname']);
    $lastName = trim($_POST['lname']);
    $txtuname = trim($_POST['uname']);
    $txtemail = trim($_POST['email']);
    $busName = trim($_POST['busname']);
    $busEmail = trim($_POST['busemail']);
    $busAddress = trim($_POST['busaddress']);
    $busSuite = trim($_POST['bussuite']);
    $busCity = trim($_POST['buscity']);
    $busState = trim($_POST['busstate']);
    $busZip = trim($_POST['buszip']);

    if($firstName == NULL) {
      $msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Please enter your first name to continue!</div>";
    }
    elseif ($lastName == NULL){
        $msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Please enter your last name to continue!</div>";
    }
    elseif ($txtuname == NULL){
        $msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Please enter your username to continue!</div>";
   }
   elseif ($txtemail == NULL){
        $msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Please enter your email to continue!</div>";
    }
    elseif ($busName == NULL) {
         $msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Please enter your business name to continue!</div>";
    }
    elseif ($busEmail == NULL) {
        $msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Please enter your business email to continue!</div>";
    }

    $msg = "<div class='alert alert-success'><button class='close' data-dismiss='alert'>&times;</button> You are finally on the right path!</div>";
}
else {
$msg = "<div class='alert alert-danger'><button class='close' data-dismiss='alert'>&times;</button> Something is really screwed up!</div>";
}

成功并返回正确的结果......好!这有望证明VSTS和Azure帐户之间的身份验证正在按预期工作。

当我尝试以下命令时:

Get-AzureRmResourceGroup

我得到了这个:

Start-AzureAutomationRunbook -AutomationAccountName "automationaccountname" -Name "RunbookName"

但是,VSTS已经自动执行以下命令:

No default subscription has been designated. Use Select-AzureSubscription -Default <subscriptionName> to set the default subscription.

我不确定我需要执行什么,因为上一个命令已经选择了订阅。任何线索?

1 个答案:

答案 0 :(得分:0)

所以这就是事情。此时,PowerShell有两个Azure模块。有Azure和AzureRM。 Azure模块处理“Classic”模型资源,而AzureRM模块使用ARM(Azure资源管理)资源。它们中的每一个或多或少地彼此独立地操作,在这里和那里具有小的重叠。这里的关键是以*-AzureRM*开头的任何内容都与AzureRM模块相关。这些cmdlet使用Add-AzureRMAccount cmdlet和Set-AzureRMContext的登录信息(Select-AzureRMSubscription是别名)。如果您运行的命令不是以“*-AzureRM”开头,那么您很可能需要通过Add-AzureAccount cmdlet登录经典模块才能执行命令,或者如果您已经完成了您可以使用Select-AzureSubscription cmdlet指定要使用的订阅。

最有可能修复:仔细检查这是否是Classic Runbook。如果它不说Classic,请尝试使用AzureRM命令:

Start-AzureRmAutomationRunbook -AutomationAccountName "automationaccountname" -Name "RunbookName"

如果这不起作用,那么您需要确保已登录到经典模块,并且可以看到您的订阅:

Get-AzureSubscription -SubscriptionId 12345678-1234-1234-1234-1234567890AB

如果您可以看到订阅,则可以运行相同的操作,只需将其传递给Select-AzureSubscription

Get-AzureSubscription -SubscriptionId 12345678-1234-1234-1234-1234567890AB | Select-AzureSubscription

如果未列出您的订阅,则可以使用Add-AzureAccount cmdlet使用与该订阅关联的帐户登录Azure,然后根据需要重复Get/Select-Subscription cmdlet。