-1

I have an automation account with run as account set up. I am trying to use it to run a VM scaling runbook i have imported from the gallery in the portal (source here: enter link description here).

I am getting the following error, and I can not find out much about what exactly it means:

Add-AzureRmAccount : Cannot validate argument on parameter 'TenantId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At line:106 char:11 + -TenantId $runAsConnectionProfile.Tenant.Id ` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Add-AzureRmAccount], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.Profile.AddAzureRMAccountCommand

It looks like the RunAsConnection doesn't have a tenant ID, but when I open up the run as account in the portal the AzureRunAsConnection looks to have a tenant id.

Can someone explain why this error could be happening?

abinitio
  • 609
  • 6
  • 20
  • I'm able to execute the runbook without errors. Try printing the `$runAsConnectionProfile` object, or just the `TenantId` property and see what you get. If the error persists, you can try recreating the `RunAsAccount`. – Bhargavi Annadevara Oct 06 '21 at 05:10
  • Managed to get it fixed. There is an error in the runbook: Tenant.Id should be TenantId. ANd I switched to `Get-AzVM ` rather than `Get-AzureRmVm ` – abinitio Oct 06 '21 at 07:10
  • If you're referring to [this line](https://github.com/azureautomation/virtual-machine-scheduled-scaling/blob/master/VirtualMachineScheduledScaling.ps1#L106), then it is `TenantId` already. – Bhargavi Annadevara Oct 06 '21 at 07:16
  • @abinitio: Glad that you were able to fix your issues. Could you please post your answer in the answer section. That would help other community members who would be facing same similar issue. – Madhuraj Vadde Oct 06 '21 at 19:02

1 Answers1

0

Posting the comment by @abinitio as answer to help other community members who could be facing the similar issue.

If you check this line then you will find that we should be using TenentID instead of Tenent.Id for RunAsConnection.

And if you are getting error using Get-AzureRmVm while trying to get your VMs then try using Get-AzVM. Get-AzVM is the newest form of the command, for managing ARM resources, and supersedes Get-AzureRmVM.

SauravDas-MT
  • 1,224
  • 1
  • 4
  • 10