Advertisement
Guest User

Untitled

a guest
May 24th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. workflow Start-ITCampManagementVMs
  2. {
  3. Param (
  4. # Name of the target Azure subscription.
  5. [Parameter(Mandatory=$True)]
  6. [String]$SubscriptionName = "MSFT IT Camp Stage",
  7. [Parameter(Mandatory=$False)]
  8. [String]$AdminUsername = "adm_camp",
  9. [Parameter(Mandatory=$False)]
  10. [String]$AdminPassword = "Azureisttoll!",
  11. [Parameter(Mandatory=$False)]
  12. [String]$Location = "West Europe", # Get-AzureLocation
  13. [Parameter(Mandatory=$True)]
  14. [Int]$NumberOfVMs = 30,
  15. [Parameter(Mandatory=$False)]
  16. [String]$NamePrefix = "itc0202"
  17. )
  18.  
  19. # Get the Azure connection asset that is stored in the Automation service based on the name that was passed into the runbook
  20. $AzureConn = Get-AutomationConnection -Name $SubscriptionName
  21. # Get the Azure management certificate that is used to connect to this subscription
  22. $Certificate = Get-AutomationCertificate -Name $AzureConn.AutomationCertificateName
  23. # Set the Azure subscription configuration
  24. Set-AzureSubscription -SubscriptionName $SubscriptionName -SubscriptionId $AzureConn.SubscriptionID -Certificate $Certificate
  25. # Select the Azure subscription.
  26. Select-AzureSubscription -SubscriptionName $SubscriptionName
  27.  
  28. # Pre-configured images
  29. # Get latest image for Windows Server 2012 R2.
  30. $imageName = Get-AzureVMImage |
  31. Where-Object -Property ImageFamily -eq "Windows Server 2012 R2 Datacenter" |
  32. Sort-Object -Property PublishedDate -Descending |
  33. Select-Object -ExpandProperty ImageName -First 1
  34.  
  35. $randomPart = "{0:ffff}" -f $(Get-Date)
  36.  
  37. # Create account names.
  38. $instanceNames = InlineScript {
  39. $instanceNames = @()
  40. $prefix = $Using:NamePrefix
  41.  
  42. # Create a short prefix, because the host name cannot longer than 15 characters.
  43. $shortPrefix = $prefix.Substring(0, ([System.Math]::Min($prefix.Length,12)))
  44. for ($i = 0; $i -lt $Using:NumberOfVMs; $i++) {
  45. $counter = "{0:00}" -f $i
  46.  
  47. # Create a host name and a DNS safe name for the lcoud service and storage account.
  48. $instanceNames += @{HostName = "$shortPrefix-$counter";
  49. DnsSafe = "$prefix$Using:randomPart$counter"}
  50. }
  51. $instanceNames
  52. }
  53.  
  54. Checkpoint-Workflow
  55.  
  56. foreach ($instance in $instanceNames) {
  57. Write-Warning "Instance.DnsSafe: $($instance.DnsSafe)"
  58. Write-Warning "Instance.HostName: $($instance.HostName)"
  59.  
  60. New-AzureStorageAccount -Location $Location -StorageAccountName $instance.DnsSafe -Type Standard_LRS
  61.  
  62. Checkpoint-Workflow
  63.  
  64. Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $instance.DnsSafe
  65.  
  66. New-AzureQuickVM -ImageName $imageName -ServiceName $instance.DnsSafe -Windows -AdminUsername $AdminUsername -InstanceSize Basic_A2 -Location $Location -Name $instance.HostName -Password $AdminPassword
  67.  
  68. Checkpoint-Workflow
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement