Maximize Your Cloud Reach: Connect On-Premises Machines to Azure Arc with PowerShell

Introduction

There are several ways to connect machines to Azure Arc, including using the Microsoft Monitoring Agent, as I discussed in a previous blog post. However, not all customers use Azure Update Management, so alternative methods for onboarding Azure Arc agents may be needed. These alternative methods can help ensure that you can connect your machines to Azure Arc, regardless of whether they use Azure Update Management.

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

In this blog post, I will show how to use Az.ConnectedMachine PowerShell module to onboard machines to Azure Arc. The Az.ConnectedMachine module is an official module from Microsoft that provides a range of commands for managing and monitoring Azure Arc-connected machines. The current version (0.10.0) of the Az.ConnectedMachine module includes 25 different commands, which can be used to perform a wide variety of tasks related to Azure Arc-connected machines.

Az.ConnectedMachine module commands:

				
					Connect-AzConnectedMachine
Get-AzConnectedExtensionMetadata
Get-AzConnectedLicense
Get-AzConnectedMachine
Get-AzConnectedMachineExtension
Get-AzConnectedNetworkSecurityPerimeterConfiguration
Get-AzConnectedPrivateLinkScope
Install-AzConnectedMachinePatch
Invoke-AzConnectedAssessMachinePatch
Invoke-AzConnectedReconcileNetworkSecurityPerimeterConfiguration
New-AzConnectedLicense
New-AzConnectedLicenseDetail
New-AzConnectedMachineExtension
New-AzConnectedPrivateLinkScope
Remove-AzConnectedLicense
Remove-AzConnectedMachine
Remove-AzConnectedMachineExtension
Remove-AzConnectedPrivateLinkScope
Set-AzConnectedLicense
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

				
			

Required Azure Resource Providers

Before connecting machines to Azure Arc, you need to register the following resource providers at the subscription level:

				
					Register-AzResourceProvider -ProviderNamespace Microsoft.HybridCompute
Register-AzResourceProvider -ProviderNamespace Microsoft.GuestConfiguration
Register-AzResourceProvider -ProviderNamespace Microsoft.HybridConnectivity
Register-AzResourceProvider -ProviderNamespace Microsoft.AzureArcData
Register-AzResourceProvider -ProviderNamespace Microsoft.Compute
				
			

These registrations are required to enable the necessary Azure Arc functionalities for your on-premises or remote machines.

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

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.

Conclusion

Connecting machines to Azure Arc doesn’t have to be a complex process. With the Az.ConnectedMachine PowerShell module, you can easily onboard machines to Azure Arc, regardless of whether they’re local or remote. So why wait? Start leveraging the power of Azure Arc today!

Leave a Comment

Contact me

If you’re interested in learning about Maximize Your Cloud Reach: Connect On-Premises Machines to Azure Arc with PowerShell. I can help you understand how this solution can benefit your organization and provide a customized solution tailored to your specific needs.

Table of Contents