Created on

Windows Admin Center – Bulk enable on servers via PowerShell


Windows Admin Center is a great tool for managing Windows Servers from the Azure Portal. But how to enable this great tool on many servers at the same time. I have written a small script that does the job.

The script will enable WAC on all servers in the resource group defined on script execution (we could easily change this to subscription or based on tag if needed). The script handles both virtual machines in Azure and Azure Arc onboarded machines (physical and virtual outside of Azure).

Note that on virtual machines running in Azure, you need access to the target VM’s IP address (either LAN or WAN IP) on port 6516. This requirement is not present on Azure Arc, since the Azure Arc client handles the communication between the portal and the target machine. Also note that Windows Admin Center for Arc onboarded machines is in preview.

Connect-AzAccount

$RG = Read-Host "Input Resource Group where VM or Arc Machines resides"
$extensionName = "AdminCenter"
$extensionType = "AdminCenter"
$publisher = "Microsoft.AdminCenter"
$version = "0.62.0.0" # For Azure Arc Machines
$settings = @{ "port" = "6516" }

$outputTable = New-Object 'System.Collections.Generic.List[System.Object]'



# Enable WAC for all Azure IaaS in defined Resource Group
$allVMs = Get-AzVM -ResourceGroupName $RG

Foreach ($VM in $allVMs)
{
   $install = Set-AzVMExtension -Name $extensionName `
    -ResourceGroupName $RG `
    -Location $VM.location `
    -VMName $VM.Name `
    -Publisher $publisher `
    -ExtensionType $extensionType `
    -TypeHandlerVersion "0.0" `
    -Settings $settings

    $objoutputTable = [PSCustomObject]@{
        Type            = "AzureVM"
        Name            = $VM.Name
        RG              = $VM.ResourceGroupName
        WACStatus		= $install.IsSuccessStatusCode
    }
    $outputTable.add($objoutputTable)
}

# Enable WAC for all Azure Arc Machines in defined Resource Group
$allArcVMs = Get-AzConnectedMachine -ResourceGroupName $RG

Foreach ($arcVM in $allArcVMs)
{
    $install = New-AzConnectedMachineExtension -Name $extensionName `
    -ResourceGroupName $RG `
    -MachineName $arcVM.Name `
    -Location $arcVM.location `
    -Publisher $publisher `
    -Settings $settings `
    -ExtensionType $extensionType `
    -TypeHandlerVersion "0.62.0.0"

    $objoutputTable = [PSCustomObject]@{
        Type            = "ArcMachine"
        Name            = $VM.Name
        RG              = $VM.ResourceGroupName
        WACStatus		= $install.IsSuccessStatusCode
    }
    $outputTable.add($objoutputTable)
}

$outputTable | Export-CSV -Path "./WACInstallState-$RG.csv" -Delimiter "," -NTI