Windows Azure – Exam preperation Links 70-533, 70-532 – Part 4


Staged Deployment on Microsoft Azure Websites

http://azure.microsoft.com/en-us/documentation/articles/web-sites-staged-publishing/

New-AzureWebsite

http://msdn.microsoft.com/en-us/library/azure/dn495157.aspx

Azure Web Sites – Continuous Deployment with Staged Publishing

http://ruslany.net/2014/03/azure-web-sites-continuous-deployment-with-staged-publishing/

Azure Powershell Script to list Sites / Staging / Deployment Slots for Web Hosting Plans

http://blogs.msdn.com/b/waws/archive/2014/11/05/azure-powershell-script-to-list-sites-staging-deployment-slots-for-web-hosting-plans-whp.aspx

Azure Websites Web Hosting Plans In-Depth Overview

http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/

Changing Azure Hosting Plans with PowerShell

http://blogs.msdn.com/b/shad_phillips/archive/2014/11/06/changing-azure-hosting-plans-with-powershell.aspx

Creating Azure Web Site using PowerShell

$WebSiteTitle = "TestWebSiteJY"
$Location = "East US"
New-AzureWebsite -Location $Location -Name $WebSiteTitle -
$WebSiteTitle = "azuretestjy123(staging)"
$WebSite = Get-AzureWebSite -Name $WebSiteTitle
$WebSite | Select Name, NetFrameworkVersion, AppSettings

#Adding App Setting to Azure Web Site Staging Slot
$CustomerAppSetting = @{"SiteUrl"="http://portal.contoso.com"}
Set-AzureWebsite $WebSiteTitle -AppSettings $CustomerAppSetting
Restart-AzureWebsite $WebSiteTitle

Enable IIS On Azure VM using Remote PowerShell


With Simple modification you can do anything you want.

 

# Define functions:
Function InstallWinRMCertificateForVM ($servicename, $svrname)
{
    Write-Host "Installing WinRM Certificate for remote access: $servicename $svrname"
    $WinRMCert = (Get-AzureVM -ServiceName $servicename -Name $svrname | select -ExpandProperty vm).DefaultWinRMCertificateThumbprint
	$AzureX509cert = Get-AzureCertificate -ServiceName $servicename -Thumbprint $WinRMCert -ThumbprintAlgorithm sha1

	$certTempFile = [IO.Path]::GetTempFileName()
	$AzureX509cert.Data | Out-File $certTempFile

	# Target The Cert That Needs To Be Imported
	$CertToImport = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certTempFile

	$store = New-Object System.Security.Cryptography.X509Certificates.X509Store "Root", "LocalMachine"
	$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadWrite)
	$store.Add($CertToImport)
	$store.Close()
	
	Remove-Item $certTempFile
}

$adminUsername  = '<username>'
$adminPassword = '<password>'

$vmname       = "HQServer1"
$cloudsvcName =  "HQServer1"

# Install the WinRM Certificate first to access the VM via Remote PS
InstallWinRMCertificateForVM $cloudsvcName $vmname

# Return back the correct URI for Remote PowerShell
$uri = Get-AzureWinRMUri -ServiceName $cloudsvcName -Name $vmname
$SecurePassword = $adminPassword | ConvertTo-SecureString -AsPlainText -Force
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $adminUsername,$SecurePassword

# Test Remote Script 
Invoke-Command -ConnectionUri $uri.ToString() -Credential $credential -ScriptBlock {
  Get-ChildItem c:\
}

# Install IIS
Invoke-Command -ConnectionUri $uri.ToString() -Credential $credential -ScriptBlock {
  Install-WindowsFeature -Name Web-Server -IncludeManagementTools -Source C:\Windows\WinSxS
}

# Disable Windows Firewall:
Invoke-Command -ConnectionUri $uri.ToString() -Credential $credential -ScriptBlock {
  Set-NetFirewallProfile -All -Enabled False 
}

Assign Availability Set to Existing Azure Virtual Machines


Add-AzureAccount
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile 'D:\Windows Azure MSDN - Visual Studio Ultimate-12-2-2014-credentials.publishsettings'
Get-AzureSubscription
Set-AzureSubscription -SubscriptionName "Windows Azure MSDN - Visual Studio Ultimate"

$VMHQServer1 = Get-AzureVM -Name HQServer1 -ServiceName "HQServer1"
$VMHQServer1 | Set-AzureAvailabilitySet -AvailabilitySetName WestAvailabilitySet | Update-AzureVM

$VMBranchServer1 = Get-AzureVM -Name BranchServer1 -ServiceName "BranchServer1"
$VMBranchServer1 | Set-AzureAvailabilitySet -AvailabilitySetName WestAvailabilitySet | Update-AzureVM

Get-AzureVM | Select Name, AvailabilitySetName, DNSName

Launch or Save Azure VM Remote Desktop Files using PowerShell


#Get VM Names
$VM1Name = "HQServer1"
$VM2Name = "BranchServer1"
#You can also seperate the Service names if they are different.
#Get VMs
$VM1 = Get-AzureVM -ServiceName $VM1Name -Name "HQServer1"
$VM2 = Get-AzureVM -ServiceName $VM2Name -Name "BranchServer1"
#Save to Desired folders
Get-AzureRemoteDesktopFile -Name $VM1Name -ServiceName $VM1.ServiceName -LocalPath D:\Azure\VM1.rdp
Get-AzureRemoteDesktopFile -Name $VM2Name -ServiceName $VM2.ServiceName -LocalPath D:\Azure\VM2.rdp
#Launch Directly
Get-AzureRemoteDesktopFile -Name $VM1Name -ServiceName $VM1.ServiceName -LocalPath -Launch
Get-AzureRemoteDesktopFile -Name $VM2Name -ServiceName $VM2.ServiceName -LocalPath -Launch