Hi @Dio Wang ,
I was also able to reproduce the error that you have provided. If we run the below 2 commands in any local machine then it works without any error but it fails when executed from an Azure Automation runbook. So, the issue is, in runbook $AppGw is holding the value of type "Deserialized.Microsoft.Azure.Commands.Network.Models.PSApplicationGateway" where as it's expected to hold the value of type "Microsoft.Azure.Commands.Network.Models.PSApplicationGateway". Hence the error.
$AppGw = Get-AzApplicationGateway -Name test01 -ResourceGroupName brain;
Stop-AzApplicationGateway -ApplicationGateway $AppGw;
I will share this feedback internally with Azure Automation product and engineering team to fix the issue. However, as a workaround you may use the below runbook which is working without any issues when I have tested in my environment. Let me know if you face any issues while you try.
workflow MyFirstRunbook-Workflow
{
Disable-AzContextAutosave -Scope Process
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $Conn.TenantID -ApplicationId $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint
Stop-AzApplicationGateway -ApplicationGateway (Get-AzApplicationGateway -Name test01 -ResourceGroupName brain)
}