简体   繁体   中英

Azure Automation Runbooks using Get-Credential without parameters

There are several Runbooks examples in the Azure Runbook Gallery, such as:

  • Deploy a Windows Azure Web Site Pointing to a SQL Database and Storage Account

that use the following syntax with Get-Credential :

$credential = Get-Credential

which implies that the command should prompt for the credentials -- but this fails in a Runbook with the following message:

Get-Credential : Cannot process command because of one or more missing mandatory parameters: Credential.

The credentials that are desired here are for this purpose:

# Get credentials from user to setup administrator access to new SQL Azure Server

which then should get used in downstream cmdlet calls in the Runbook such as

$databaseServer = New-AzureSqlDatabaseServer -AdministratorLogin $credential.UserName `
    -AdministratorLoginPassword $credential.GetNetworkCredential().Password -Location $Location

But because Get-Credential fails the downstream calls fail.

What I am doing wrong?

Why does a Runbook in the Gallery have statements that seem to be incompatible (prompt for Credentials) with allowable Runbook behaviors?

So with Azure Automation, you would create a credential asset (for example, named AzureAdmin) and then you would reference that in the runbook, to get those credentials:

$cred = Get-AutomationPSCredential -Name AzureAdmin

As for the reference script, I suppose, it was just added to the runbook gallery without any verification, so in reality its not Azure Automation friendly

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM