question

SPXADMIN-5031 avatar image
0 Votes"
SPXADMIN-5031 asked ·

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

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
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @SPXADMIN-5031,

Did you get chance to review the below information? Let me know if you have any further queries regarding it.

0 Votes 0 ·
tbgangav-MSFT avatar image
0 Votes"
tbgangav-MSFT answered ·

Hi @SPXADMIN-5031,

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>>


image.png (61.4 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

tbgangav-MSFT avatar image
0 Votes"
tbgangav-MSFT answered ·

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.


image.png (76.7 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.