Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- workflow Start-ITCampManagementVMs
- {
- Param (
- # Name of the target Azure subscription.
- [Parameter(Mandatory=$True)]
- [String]$SubscriptionName = "MSFT IT Camp Stage",
- [Parameter(Mandatory=$False)]
- [String]$AdminUsername = "adm_camp",
- [Parameter(Mandatory=$False)]
- [String]$AdminPassword = "Azureisttoll!",
- [Parameter(Mandatory=$False)]
- [String]$Location = "West Europe", # Get-AzureLocation
- [Parameter(Mandatory=$True)]
- [Int]$NumberOfVMs = 30,
- [Parameter(Mandatory=$False)]
- [String]$NamePrefix = "itc0202"
- )
- # Get the Azure connection asset that is stored in the Automation service based on the name that was passed into the runbook
- $AzureConn = Get-AutomationConnection -Name $SubscriptionName
- # Get the Azure management certificate that is used to connect to this subscription
- $Certificate = Get-AutomationCertificate -Name $AzureConn.AutomationCertificateName
- # Set the Azure subscription configuration
- Set-AzureSubscription -SubscriptionName $SubscriptionName -SubscriptionId $AzureConn.SubscriptionID -Certificate $Certificate
- # Select the Azure subscription.
- Select-AzureSubscription -SubscriptionName $SubscriptionName
- # Pre-configured images
- # Get latest image for Windows Server 2012 R2.
- $imageName = Get-AzureVMImage |
- Where-Object -Property ImageFamily -eq "Windows Server 2012 R2 Datacenter" |
- Sort-Object -Property PublishedDate -Descending |
- Select-Object -ExpandProperty ImageName -First 1
- $randomPart = "{0:ffff}" -f $(Get-Date)
- # Create account names.
- $instanceNames = InlineScript {
- $instanceNames = @()
- $prefix = $Using:NamePrefix
- # Create a short prefix, because the host name cannot longer than 15 characters.
- $shortPrefix = $prefix.Substring(0, ([System.Math]::Min($prefix.Length,12)))
- for ($i = 0; $i -lt $Using:NumberOfVMs; $i++) {
- $counter = "{0:00}" -f $i
- # Create a host name and a DNS safe name for the lcoud service and storage account.
- $instanceNames += @{HostName = "$shortPrefix-$counter";
- DnsSafe = "$prefix$Using:randomPart$counter"}
- }
- $instanceNames
- }
- Checkpoint-Workflow
- foreach ($instance in $instanceNames) {
- Write-Warning "Instance.DnsSafe: $($instance.DnsSafe)"
- Write-Warning "Instance.HostName: $($instance.HostName)"
- New-AzureStorageAccount -Location $Location -StorageAccountName $instance.DnsSafe -Type Standard_LRS
- Checkpoint-Workflow
- Set-AzureSubscription -SubscriptionName $SubscriptionName -CurrentStorageAccountName $instance.DnsSafe
- New-AzureQuickVM -ImageName $imageName -ServiceName $instance.DnsSafe -Windows -AdminUsername $AdminUsername -InstanceSize Basic_A2 -Location $Location -Name $instance.HostName -Password $AdminPassword
- Checkpoint-Workflow
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement