PowerShell Workflow Runbook that Automatically start the virtual machine (on scheduled time) error

SPX ADMIN 1 Reputation point
2021-03-08T13:22:28.44+00:00

Hello,

I am trying to create a PowerShell Workflow runbook that automatically start the virtual machine, but I am getting this error : cannot validate argument on parameter 'TenantId'

I was following this link : https://akril.net/auto-start-and-shutdown-a-vm-in-azure-to-improve-cost-management/

this is the code

75465-2021-03-08-14-02-18.png

this is the error

75330-2021-03-08-14-03-51.png

thanks for your help

Azure Automation
Azure Automation
An Azure service that is used to automate, configure, and install updates across hybrid environments.
1,113 questions
{count} votes

3 answers

Sort by: Most helpful
  1. tbgangav-MSFT 10,376 Reputation points
    2021-03-09T12:46:09.203+00:00

    Hi @SPX ADMIN ,

    I have tried to reproduce the issue but was successfully about to login using Add-AzureRMAccount. Error says that $Conn.TenantID is null or empty so I would recommend to try printing $Conn.TenantID and see if it prints TenantID or not.

    workflow StartGC  
    {  
    $Conn = Get-AutomationConnection -Name AzureRunAsConnection  
    Write-Output $Conn.TenantID  
    Add-AzureRMAccount -ServicePrincipal -TenantId $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint  
    Write-Output "end"  
    }  
    

    I was able to see below output:
    75872-image.png

    <<Continued in next comment>>

    0 comments No comments

  2. tbgangav-MSFT 10,376 Reputation points
    2021-03-09T12:57:03.233+00:00

    In case, if it turns out to be null or empty then check what's in $Conn variable as shown below.

    workflow StartGC
    {
    $Conn = Get-AutomationConnection -Name AzureRunAsConnection
    Write-Output $Conn
    Add-AzureRMAccount ......
    ...
    ...
    }
    

    I was able to see below output:

    75848-image.png

    Even then if the output is null or empty then that means $Conn variable is null or empty. So, I would recommend to verify in "Modules" tile of your Automation account if status of module "Orchestrator.AssetManagement.Cmdlets" is "Available" with version "1.0" or not. We are validating this because Get-AutomationConnection cmdlet is part of this module.

    0 comments No comments

  3. Krzysztof Pospiech 1 Reputation point
    2022-10-11T09:07:17.027+00:00

    Had the same problem... in the end it turned out that the automation account needed adjustment in 'Account Settings' / 'Run as accounts'. I added the one below and the error is gone:

    249295-image.png

    0 comments No comments