powershell - How to specify DNS name (Domain Name) prefix in Azure ASM? -
this script use create classic (asm) vm in azure
param( [switch] $help = $false, $azurepassword, $azureusername , $azuresubscriptionname , $vmimagename, $azurestorageaccountname, $azureresourcegroupname, $vmsize, $vmname, $vmadministratorusername, $vmadministratorpassword, $vnetname, $vnetsubnetname ) #preparation steps clear-host $starttime = get-date write-host -foregroundcolor cyan "this script create classic vm '$vmname'" write-host "script started ($starttime)" detectpowershellversion 4 $azurepassword = $azurepassword | convertto-securestring -asplaintext -force $azurecredentials = new-object -typename system.management.automation.pscredential -argumentlist $azureusername,$azurepassword disable-azuredatacollection -warningaction silentlycontinue #1 write-host -foregroundcolor cyan "step 1: logging in azure..." add-azureaccount -credential $azurecredentials | out-null write-host "logged in." #2 write-host -foregroundcolor cyan "step 2: selecting subscription..." select-azuresubscription -subscriptionname $azuresubscriptionname -current new-azurestorageaccount -storageaccountname $azurestorageaccountname -label $azurestorageaccountname -location "north europe" -erroraction silentlycontinue set-azuresubscription -subscriptionname $azuresubscriptionname -currentstorageaccountname $azurestorageaccountname write-host "selected subscription = $((get-azuresubscription -current).subscriptionname)" write-host "selected storage account name = $azurestorageaccountname " #3 write-host -foregroundcolor cyan "step 3: locating vmimage subscription..." $vmimage = (get-azurevmimage | { $_.label -like "$($vmimagename)*" } | sort-object publisheddate -descending)[0] write-host "selected image = $($vmimage.label)" write-host "selected image os = $($vmimage.os)" #4 write-host -foregroundcolor cyan "step 4: locating requested size..." write-host "requested size = $vmsize" $vmconfig = new-azurevmconfig -name $vmname -instancesize $vmsize -imagename $vmimage.imagename #5 write-host -foregroundcolor cyan "step 5: creating credentials vm..." if ($vmimage.os -eq "windows") { $vmprovision = add-azureprovisioningconfig -windows -adminusername $vmadministratorusername -password $vmadministratorpassword -vm $vmconfig } else #linux { $vmprovision = add-azureprovisioningconfig -linux -linuxuser $vmadministratorusername -password $vmadministratorpassword -vm $vmconfig } write-host "credentials created. username = $vmadministratorusername password = *******" #6 delete vm if exists write-host -foregroundcolor cyan "step 6: deleting vm '$vmname' if exists..." $vmstatus = get-azurevm -servicename $azureresourcegroupname -name $vmname if ($vmstatus) { write-host "vm $vmname detected." write-host "stopping $vmname" stop-azurevm -servicename $azureresourcegroupname -name $vmname -force write-host "deleting vm $vmname" remove-azurevm -servicename $azureresourcegroupname -name $vmname -deletevhd } else { write-host "vm $vmname not detected." } #7 provision vm! write-host -foregroundcolor cyan "step 7: creating virtual machine in azure..." write-host "this take while" write-host "starting creation of vm $vmname" write-host "using vnet $vnetname , subnet $vnetsubnetname" set-azuresubnet -subnetnames $vnetsubnetname -vm $vmconfig | out-null new-azureservice -servicename $azureresourcegroupname -location "north europe" -erroraction silentlycontinue -warningaction silentlycontinue $vmresult = $vmprovision | new-azurevm -servicename $azureresourcegroupname -waitforboot -vnetname $vnetname # end $endtime = get-date write-host "creation of vm $vmname finished ($endtime)" $elapsedtime = new-timespan $starttime $endtime write-host -foregroundcolor cyan "success: vm creation time = $elapsedtime" exit 0
i call parameters (among others)
- azureresourcegroupname "testbananas"
- vmname "testoranges"
it works ok , creates vm can see in screenshot
as can see vmname testoranges , created in service (resource group) testbananas.
but dns name created default testbananas.cloudapp.net want testoranges.cloudapp.net or specify. think dns name being populated default.
so question is:
how specify dns name prefix in azure asm?
i have found lot of information use custom dns or join domain... don't want it, want specify custom dnsname.cloudapp.net because plan have several vm in same resource group
note 1: when execute script have warning:
warning: no deployment found in service: 'testbananas'
note 2: if create second vm "test-apples" dns name , publicip same "test-oranges", although private ip different. external ssh port test-oranges 55525 , test-apples 53456. if ssh in both , execute "hostname" names matching...
definetively there wrong script :-(
in #7 provision vm! have
new-azureservice -servicename $azureresourcegroupname ` -location "north europe" ` -erroraction silentlycontinue ` -warningaction silentlycontinue
changing $azureresourcegroupname
testoranges
give result seek
the problem having due fact asm doesn't use resource groups in same way arm does. (it's use of them inconsistent -it largely own thing names of)
Comments
Post a Comment