I have a Azure trial setup on my Microsoft account - I’m trying to use my Microsoft Account as a credential asset under Azure automation, but im recieving the error below.
Is there any way I can use this trial to mess around with azure automation?
Add-AzureAccount : -Credential parameter can only be used with Organization ID credentials. For more information, please refer to http://go.microsoft.com/fwlink/?linkid=331007&clcid=0x409
for more information about the difference between an organizational account and a Microsoft account.
At Get-AzureVMTutorial:22 char:22
+
+ CategoryInfo : CloseError: (:) [Add-AzureAccount], AadAuthenticationFailedException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.Profile.AddAzureAccount
+ PSComputerName : [localhost]
Could not authenticate to Azure using the credential asset 'AzureCreds'. Make sure the user name and password are correct.
At Get-AzureVMTutorial:24 char:24
+
+ CategoryInfo : InvalidResult: (:) [], Exception
+ FullyQualifiedErrorId : JobStateFailed
You’ll want to use Login-AzureAccount instead. It’ll pop up a web browser where you sign on with your Microsoft account credentials. This can’t be automated with a PSCredential object. I have no idea why.
Do you mean Login-AzureRMAccount? I can’t actually get the Login-AzureAccount cmdlet.
I’m actually just trying to get the Get-AzureVMTutorial.ps1 working in the Azure Automation runbook. Here is the original:
workflow Get-AzureVMTutorial
{
#The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
$CredentialAssetName = 'AzureCreds'
#Get the credential with the above name from the Automation Asset store
$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
if(!$Cred) {
Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
}
#Connect to your Azure Account
$Account = Add-AzureAccount -Credential $Cred
if(!$Account) {
Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."
}
#TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.
#Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here"
#Get all the VMs you have in your Azure subscription
$VMs = Get-AzureVM
#Print out up to 10 of those VMs
if(!$VMs) {
Write-Output "No VMs were found in your subscription."
} else {
Write-Output $VMs[0..9]
}
}
Here are my changes:
workflow Get-AzureVMTutorial
{
##The name of the Automation Credential Asset this runbook will use to authenticate to Azure.
#$CredentialAssetName = 'AzureCreds'
#
##Get the credential with the above name from the Automation Asset store
#$Cred = Get-AutomationPSCredential -Name $CredentialAssetName
#if(!$Cred) {
# Throw "Could not find an Automation Credential Asset named '${CredentialAssetName}'. Make sure you have created one in this Automation Account."
#}
#
##Connect to your Azure Account
#$Account = Add-AzureAccount -Credential $Cred
$Account = Login-AzureRmAccount
if(!$Account) {
Throw "Could not authenticate to Azure using the credential asset '${CredentialAssetName}'. Make sure the user name and password are correct."
}
#TODO (optional): pick the right subscription to use. Without this line, the default subscription for your Azure Account will be used.
#Select-AzureSubscription -SubscriptionName "TODO: your Azure subscription name here"
#Get all the VMs you have in your Azure subscription
$VMs = Get-AzureVM
#Print out up to 10 of those VMs
if(!$VMs) {
Write-Output "No VMs were found in your subscription."
} else {
Write-Output $VMs[0..9]
}
}
Unfortunately, when I changed this, it has thrown the following error:
C:\(my home directory)\AutomationWorkspace\Free Trial - (my subscription guid)\TestVMNetwork\Automation\Get-AzureVMTutorial.ps1 : Object reference not set to an instance of an
object.
+ CategoryInfo : NotSpecified: (:) [Get-AzureVMTutorial.ps1], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Get-AzureVMTutorial.ps1
Any ideas? I know the tool is fairly new so im wondering if there’s some tweaking that I need to do or something I’m missing…
When you access Azure resources using the Azure cmdlets, you need to provide authentication to your Azure subscription. In Azure Automation, this is done with an organizational account in Azure Active Directory that you configure as an administrator for your subscription. You can then create a credential for this user account and use it with Add-AzureAccount in your runbook.
NOTE:
Microsoft accounts, formerly known as LiveIDs, cannot be used with Azure Automation.
Do you know if Azure Automation is meant to completely replace Set-AzureVMCustomScriptExtension and Publish-AzureVMDscConfiguration? Is one for RM and one for classic?