2 min read

Connect machines to Azure Arc with PowerShell

Connect machines to Azure Arc with PowerShell
Connect machines to Azure Arc with PowerShell

Introduction

You can connect machines to Azure Arc in a variety of ways. A month ago, I wrote about onboarding Azure Arc agents through the existing Microsoft Monitoring Agent. Currently, not every customer is using Azure Update Management, so we need different onboarding methods.

You can read more about how to do the onboarding through MMA and Azure Update Management.

This blog post will show you how to do onboarding through Az.ConnectedMachine PowerShell Module. Version 0.4.0 has 16 different commands:

Connect-AzConnectedMachine
Get-AzConnectedMachine
Get-AzConnectedMachineExtension
Get-AzConnectedPrivateLinkScope
New-AzConnectedMachineExtension
New-AzConnectedPrivateLinkScope
Remove-AzConnectedMachine
Remove-AzConnectedMachineExtension
Remove-AzConnectedPrivateLinkScope
Set-AzConnectedMachineExtension
Set-AzConnectedPrivateLinkScope
Update-AzConnectedExtension
Update-AzConnectedMachine
Update-AzConnectedMachineExtension
Update-AzConnectedPrivateLinkScopeTag

How to install Az.ConnectedMachine PowerShell module

You can install the Az.ConnectedMachine PowerShell module directly from the PowerShell console. For the module installation, use the following command:

Install-Module -Name Az.ConnectedMachine -Verbose -Force

Please remember that you need to set up the Azure Arc on your Azure environment before you can onboard any machine.

How to onboard local machine

  1. Open PowerShell as an administrator
  2. Execute the Connect-AzAccount command to connect to Azure
  3. Change the Subscription if needed using the Set-AzContext command
  4. Run the following command to onboard the local machine to Azure Arc:
$OnboardingDetails = @{
    ResourceGroupName = "RG-PROD-IT-ARC"
    Name = $env:COMPUTERNAME.ToUpper()
    Location = "West Europe"
}
Connect-AzConnectedMachine @OnboardingDetails

If you have a lot of subscriptions, then you can also use the -SubscriptionId parameter in Connect-AzConnectedMachine, which doesn't require a context change before onboarding.

How to onboard a remote machine

  1. Open PowerShell as an administrator
  2. Execute the Connect-AzAccount command to connect to Azure
  3. Change the Subscription if needed using the Set-AzContext command
  4. Create a new PowerShell Remoting session against the remote machine using the New-PSSession command
  5. Run the following command to onboard the remote machine to Azure Arc
$ServerName = "SERVER02"
$PSRemoteSession = New-PSSession -ComputerName $ServerName

$OnboardingDetails = @{
    ResourceGroupName = "RG-PROD-IT-ARC"
    Location = "West Europe"
    PSSession = $PSRemoteSession
}

Connect-AzConnectedMachine @OnboardingDetails

You can also create multiple remote sessions against many machines, and you can onboard many machines at the same time.

Need assistance implementing Azure Arc, let me know.