0

Azure runbook.

The question:

How to run/call powershell scripts on remote Azure VM via runbook? The script is placed on a remote VM.

There is no Azure AD, powershell has Az module installed.

Thank you.

1 Answer 1

3

Have your Azure Automation runbook something like shown below. It will accomplish your requirement.

$ServicePrincipalConnection = Get-AutomationConnection -Name 'AzureRunAsConnection' Add-AzAccount -ServicePrincipal -TenantId $ServicePrincipalConnection.TenantId -ApplicationId $ServicePrincipalConnection.ApplicationId -CertificateThumbprint $ServicePrincipalConnection.CertificateThumbprint $rgname ="rrrrrrrrrrrrrr" $vmname ="vvvvvvvvvvvvvv" $ScriptToRun = "ssssssssssssss" Out-File -InputObject $ScriptToRun -FilePath ScriptToRun.ps1 Invoke-AzVMRunCommand -ResourceGroupName $rgname -Name $vmname -CommandId 'RunPowerShellScript' -ScriptPath ScriptToRun.ps1 Remove-Item -Path ScriptToRun.ps1 

Note: Before you run your runbook, make sure you update "rrrrrrrrrrrrrr" with your resource group name, "vvvvvvvvvvvvvv" with your VM name and "ssssssssssssss" with the path of the script along with script name

For reference, you may refer the source from here.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.