How to join VM to a domain using Bicep and PowerShell script

moon yi 20 Reputation points
2024-06-22T08:53:09.61+00:00

Hi

I want to automate a VM to join ADDS domain using Bicep and PowerShell.

The Bicep I created uses custom script Extension to execute all the PowerShell commands to make the VM to join the domain but it fails to execute the last PS command which is Add-Computer. When it reaches this line, it just hangs indefinately. I have to terminate the run of the Bicep to get out of the indefinate hang.

The powershell code is as follows:

$domain = "myDomain" $password = "myPassword!" | ConvertTo-SecureString -asPlainText -Force $username = "$domain\myUserAccount"

$credential = New-Object System.Management.Automation.PSCredential($username,$password)

Set-DnsClientServerAddress -InterfaceIndex $ethIdx -ServerAddresses $serverIP

Add-Computer -DomainName $domain -Credential $credential -restart

Note that if I run PowerShell on its own in a powershell script file, then it works. It hangs only if the same script commands is added to bicep and run it as inline script.

Bicep template is standard template that build basic Windows 10 VM and minimum code.

Any help is appreciated.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,433 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,057 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
20,253 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 101K Reputation points MVP
    2024-06-22T09:41:19.5333333+00:00

    Hi @moon yi ,

    maybe you find this helpful to join an Azure VM to an EntraID Domain Service using Bicep:

    Deploy Azure Virtual Desktop with Project BICEP

    There is a section called Join VMs to Domain on the webpage with example code, how to get this done.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful