Skip to content

Instantly share code, notes, and snippets.

@jlattimer
Created December 5, 2014 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlattimer/95b4fe9d1913de018922 to your computer and use it in GitHub Desktop.
Save jlattimer/95b4fe9d1913de018922 to your computer and use it in GitHub Desktop.
PowerShell commands to use an existing Azure virtual machine with a reserved IP address. Suitable for a Dynamics CRM test environment with ADFS.
<# Make sure you have installed the Azure PowerShell cmdlets: https://www.windowsazure.com/en-us/manage/downloads/ and then reboot #>
<# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
The steps need to be run individually
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #>
<# Step 1: Run this first to download your publisher file from Azure #>
Get-AzurePublishSettingsFile
<# Step 2: Change the path to the file you downloaded: C:\xxx\xxx.publishsettings #>
$publisherFileLocation = "C:\xxx\xxx.publishsettings"
Import-AzurePublishSettingsFile $publisherFileLocation
<# Step 3: Input the 'Name' of the subscription from the output of the previous step #>
$subscriptionName = "Visual Studio Ultimate with MSDN"
Select-AzureSubscription -SubscriptionName $subscriptionName
<# Step 4: Run this to output the list of Azure storage accounts associated with your account #>
Get-AzureStorageAccount
<# Step 5: Input the subscription 'Name' again and the 'StorageAccountName' from the output of the previous step
when the VM gets created it will use that Azure Storage account #>
$sortageAccountName = "portalxxxxxxxxxxxxxxxxx"
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccount $sortageAccountName
<# Step 6: Create a reserved/static IP for your VM - input the name/label and the region your VM will be in #>
$reservedIPName = "CRMIP"
$reservedIPLabel = "CRMIP"
$location = “North Central US”
New-AzureReservedIP –ReservedIPName $reservedIPName –Label $reservedIPLabel –Location $location
<# Use this to remove the reserved IP if you end up not needing it #>
<# Remove-AzureReservedIP -ReservedIPName "CRMIP" -Force# >
<# Show the list of reserved IP addresses if you are interested #>
<# Get-AzureReservedIP #>
<# Step 7: Use this to list your existing Azure VM images #>
Get-AzureVMImage | Where-Object { $_.Category -eq "User" }
<# Step 8: Input the VM & cloud service names, VM size, Image name and create the VM #>
$vmName = "CRM2015"
$imageName = "ExistingCRM2015-12032014"
$cloudServiceName = "CRM2015"
$instanceSize = "ExtraLarge"
New-AzureVMConfig -Name $vmName -InstanceSize $instanceSize -Image $imageName |
Add-AzureEndpoint -Name "HTTP" -Protocol "tcp" -PublicPort 80 -LocalPort 80 |
Add-AzureEndpoint -Name "HTTPS" -Protocol "tcp" -PublicPort 443 -LocalPort 443 |
Add-AzureEndpoint -Name "HTTPS2" -Protocol "tcp" -PublicPort 444 -LocalPort 444 | <# Only if you need ADFS on the same server #>
Add-AzureEndpoint -Name "Remote Desktop" -Protocol "tcp" -PublicPort 60523 -LocalPort 3389 |
New-AzureVM -ServiceName $cloudServiceName -ReservedIPName $reservedIPName -Location $location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment