Skip to content

Instantly share code, notes, and snippets.

@waldronj
Created November 9, 2015 16:50
Show Gist options
  • Select an option

  • Save waldronj/f51f2383ac79f5cbaf36 to your computer and use it in GitHub Desktop.

Select an option

Save waldronj/f51f2383ac79f5cbaf36 to your computer and use it in GitHub Desktop.
Azure VM Provisioning and Domain Join
param(
[Parameter(Mandatory=$true)]
$Name,
[Parameter(Mandatory=$true)]
$location,
[Parameter(Mandatory=$true)]
$size,
[Parameter(Mandatory=$true)]
$vnet,
[Parameter(Mandatory=$true)]
$subnet,
[Parameter(Mandatory=$true)]
$cloudService,
[Parameter(Mandatory=$true)]
$storageAccount,
[Parameter(Mandatory=$true)]
$credential
)
$domainUser = $credential.GetNetworkCredential().Username
$domainPassword = $credential.GetNetworkCredential().Password
Set-AzureSubscription -SubscriptionName "SubScriptionNameGoesHere" -CurrentStorageAccountName $storageAccount
$image = 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-20151022-en.us-127GB.vhd'
$vmconfig = New-AzureVMConfig -name $name -InstanceSize $size -ImageName $image
$vmconfig | Add-AzureProvisioningConfig -AdminUsername 'localAdmin' -Password '***LocalAdminPassword***' -WindowsDomain -Domain 'YourDomainGoeshere' -DomainUserName $domainUser -DomainPassword $domainPassword -JoinDomain 'YourDomainGoesHere'
$vmconfig | Set-AzureSubnet -SubnetNames "SubNet"
$vm = New-AzureVM -ServiceName $cloudService -VMs $vmconfig -Verbose -VNetName $vnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment