Michael Wu

The Life of a Cloud Engineer

  • Home
  • Resume
  • Blog
  • Contact

Posted on 07.15.20

How to join a VM to a domain by PowerShell in Azure

I have a script to automate the server provisioning with VMWare on-premises. It`s tied to a WPF form and used Invoke-VMScript (VMWare PowerCLI) to handle the domain join function. You can check the post How to change IP and join a VM into domain by PowerCLI in VMware.

I don’t see many people used PowerShell to join a domain in Azure since ARM template seems to be a better way for it. I don’t use ARM as we have a custom GUI for the inputs.

Johan shared the article for Domain Join AzureRM VM’s with PowerShell, but it does not work on the new Az module with Set-AzVMExtension. I got the following error when running it…
Set-AzVMExtension : Multiple VMExtensions per handler not supported for OS type ‘Windows’. VMExtension ‘joindomain’ with handler ‘Microsoft.Compute.JsonADDomainExtension’ already
added or specified in input.

Then, I found a new cmdlet Set-AzVMADDomainExtension in the Az module. There is no examples on the help page, but I decide to give it a try. It works perfectly and is much easier. Here is how I did it.

  1. Run a PowerShell session
  2. Connect to your Azure subscription: Connect-AzAccount
  3. Run the following script
$DomainName = "your_domain_name"
$VMName = "your_VM_Name"
$credential = Get-Credential your_Domain_account
$ResourceGroupName = "your_RG_name" 

Set-AzVMADDomainExtension -DomainName $DomainName -VMName $VMName -Credential $credential -ResourceGroupName $ResourceGroupName -JoinOption 0x00000001 -Restart -Verbose

The key is the -JoinOption parameter. You need to set the fJoinOptions to 0x00000001. If this value is not specified, it will join the computer to a workgroup.

You should see the following message when the server is joined to the domain successfully.

Categories:Azure, PowerShell

Recent Posts

  • Automating Resource Restriction in Azure subscriptions with Budget Alert, Automation Account, and Azure Policy
  • How to configure the Security Center via Azure Resource Manager (ARM) template
  • How to restrict Account Operators to see the password in LAPS
  • How to join a VM to a domain by PowerShell in Azure
  • How to push an existing repository from VS Code to Azure DevOps by PowerShell

Search

Categories

  • Azure
  • IIS
  • PowerShell
  • SCCM
  • VMware
  • Windows Server

Contact

Email: [email protected] | Powered By the 太初網路

Copyright © 2024 mikewu.org Disclaimer

Connect

FacebookTwitterGoogle +Linkedin