0
votes

I want to know how to get rid of this extra account information that shows up every time i run a script in my azure automation runbook. There has to be a way to remove it, any help would be deeply appreciated.

enter image description here

1

1 Answers

1
votes

You can append Out-Null to the commands that will output your account information. It hides the output instead of sending it down the pipeline or displaying it. See other ways to ignore the output.

For example:

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    Connect-AzAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | Out-Null
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

Result

enter image description here