Download presentation
Presentation is loading. Please wait.
Published byKolby Rule Modified over 10 years ago
1
Managing Windows Azure Virtual Machines from PowerShell
Speaker Title Organization
2
Agenda Getting Started Virtual Machine Management
Disk and Image Repository Configuring Virtual Networks
3
What can you do with PowerShell?
Automation Query, Manage and Configure Virtual Machines across multiple subscriptions, cloud services and storage accounts. Provision Fully Configured Virtual Machines Domain Joined Storage and Networking Configured Virtual Networking Completely Configure VNETs from a Script
4
Setting up your Subscription
Use: Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile To Import Downloaded Publish Profile (.publishsettings) Automatically configures Subscription ID, Certificate, Service Endpoint and Subscription Name. Slide Objectives: Explain how to setup a subscription Notes: The .publishsettings file contains your subscription information, the service endpoint, subscription name and certificate. Once downloaded the Import-AzurePublishSettingsFile cmdlet will install the certificate and configure your PowerShell environment.
5
Manual Configuration of Subscription
Associate Certificate and Subscription ID $cert = Get-Item cert:\CurrentUser\My\CERTTHUMBPRINT Set-AzureSubscription 'mysub' -Certificate $cert -SubscriptionID $id Slide Objectives: Use this method if you want to specify a certificate that you have created on your own.
6
Subscription Management
Subscription Settings Persisted C:\Users\user\AppData\Roaming\Windows Azure Powershell Subscription Example <Subscription name="somesub1"> <SubscriptionId>13d83b03-6d c-3d46766c3a35</SubscriptionId> <Thumbprint>2AC8112B34CC840A30B9C2716AE840D5DC107510</Thumbprint> <ServiceEndpoint> </Subscription> Slide Objectives: Explain where subscription settings are persisted Notes: The subscription XML file supports multiple subscriptions. You can use a single PowerShell session to administer VMs and services across all of your configured subscriptions.
7
Switching Between Subscription Settings
Multiple Subscription Support Get-AzureSubscription | foreach { Select-AzureSubscription $_.SubscriptionName # Perform Management Operation Against Each Subscription } Slide Objectives: Explain how to switch contexts when scripting against multiple subscriptions Notes: Get-AzureSubscription returns all configured subscriptions and Select-AzureSubscription sets the current subscription
8
Setting the current storage account
Returns Storage Account Get-AzureStorageAccount | Select StorageAccountName Sets the Current Storage Account Set-AzureSubscription 'somesub1' -CurrentStorageAccount 'mystorage‘ Slide Objectives: Explain how to set the current storage account that the cmdlets will use. Notes: Certain cmdlets like New-AzureVM or New-AzureQuickVM require the user to specify the storage account to use. Since each subscription can contain multiple storage accounts the property name to set is CurrentStorageAccount. This allows you to easily change the storage account for the next operation. Cmdlets like New-AzureQuickVM will use this Account
9
Information Needed to create a VM
Image Name Get-AzureVMImage | select ImageName Disk Name Get-AzureDisk | select DiskName Data Center Location Get-AzureLocation Slide Objectives: To create a VM you either need to start with an Image or Disk and specify the location where to place the VM.
10
Virtual Machine Management
Quick VM Provisioning Mode Supports VM Creation in a Single Cmdlet Advanced Provisioning Configuration Mode Provision With: Endpoints, Data Disks Configure: Cache Settings for OS/Data Disks and Subnet Names Create Multiple Pre-Defined VMs in a Batch New-AzureVM -VMs $vm1, $vm2, $vm3
11
Simple VM Creation First Virtual Machine in a NEW Cloud Service (-Location specified) New-AzureQuickVM -Windows -ServiceName $svc -Name $vm1 -ImageName $wimg -Location $location -Password $pwd New Virtual Machine in an Existing Cloud Service (no –Location) New-AzureQuickVM -Windows -ServiceName $svc -Name $vm2 -ImageName $wimg -Password $pwd Creating a Linux Virtual Machine in an Existing Cloud Service New-AzureQuickVM -Linux -ServiceName $svc -Name $vm3 -ImageName $limg -LinuxUser $lu -Password $pwd Slide Objectives: Show three examples that show a key component of using the cmdlets. Notes: When you specify -Location or -AffinityGroup the cmdlets will attempt to create a new cloud service to deploy the VM to. If you do not specify either the cmdlets assume the cloud service exists in the current subscription.
12
Configuring VM at Provisioning
Create Configuration Object with New-AzureVMConfig Modify with Add-* cmdlets Add with New-AzureVM New-AzureVMConfig -Name $vm1 -InstanceSize Medium -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd | Add-AzureDataDisk -CreateNew -DiskLabel 'data' -DiskSizeInGB 10 -LUN 0 | Add-AzureEndpoint -Name 'web' -PublicPort 80 -LocalPort 80 -Protocol tcp | New-AzureVM -ServiceName $newSvc -Location $location Slide Objectives: With PowerShell you can configure various settings in a batch Notes: New New-AzureVMConfig and New-AzureVM to allow a batched creation of a VM. New-AzureVMConfig returns a configuration object that is then passed to other cmdlets to modify via the PowerShell pipeline. Finally, it is passed to New-AzureVM where the VM is created with all of the configuration specified.
13
VM Batch Creation Create Multiple Configured VMs and Pass to New-AzureVM $vm1 = New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd $vm2 = New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd $vm3 = New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd New-AzureVM -CreateService -ServiceName $cloudSvcName -VMs $vm1,$vm2,$vm3 -Location $dc Slide Objectives: It is also possible to create multiple configuration objects for multiple VMs and pass them to the New-AzureVM cmdlet as an array.
14
VM Batch Creation (using an array)
Create Multiple Configured VMs and Pass to New-AzureVM $vmcount = 5 $vms for($i = 0; $i -lt 5; $i++) { $vmn = 'myvm' + $i $vms += New-AzureVMConfig -Name $vmn -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd | Add-AzureDataDisk -CreateNew -DiskLabel 'data' -DiskSizeInGB 10 -LUN 0 | Add-AzureDataDisk -CreateNew -DiskLabel 'logs' -DiskSizeInGB 10 -LUN 1 } New-AzureVM -ServiceName $cloudSvcName -VMs $vms -Location $dc Slide Objectives: Another example of batch VM creation: using an array/loop to create multiple VMs
15
Common Settings Name AvailabilitySetName InstanceSize
The name of the Virtual Machine AvailabilitySetName The availability set (used for high availability) Slide Objectives: Explain other common settings used to provision a VM InstanceSize ExtraSmall, Small, Medium, Large, ExtraLarge
16
Windows Provisioning Options
Add-AzureProvisioningConfig Options -Windows -Password $pwd -WindowsDomain -Password $pwd -Domain $dom, -JoinDomain $fqdn, -DomainUser $domUser -DomainPassword $domPwd -MachineObjectOU $ou -DisableAutomaticUpdates -NoRDPEndpoint, -TimeZone, Certificates Slide Objectives: The Add-AzureProvisioningConfig cmdlet supports two parameter sets for Windows. Notes: -Windows allows just setting the password of the VM on boot. -WindowsDomain allows you to specify all of the settings necessary to have the VM join the domain on boot. This scenario only works in a VNET environment where the DNS specified knows how to have the VM find the domain controller. -DisableAutomaticUpdates allows for disabling automatic updates by default. Available to both parameter sets. -NoRDPEndpoint does not create the RDP endpoint on creation. Of course you can add this later through PS or the Portal. -TimeZone allows you to specify the VMs timezone on provisioning. -Certificates allows you to automatically install certificates on the VM on provisioning. Note: the certificates must already be installed in the cloud service. For an example:
17
Linux Provisioning Options
Add-AzureProvisioningConfig Options Linux -LinuxUser $user -Password $pwd -DisableSSH , -NoSSHEndpoint -SSHKeyPairs, -SSHPublicKeys installed from certificates deployed in cloud service Slide Objectives: The Add-AzureProvisioningConfig cmdlet supports one parameter set for Linux Notes: The Linux parameter set requires specifying the user name and also allows for disabling SSH on the Linux VM or just not adding the SSH endpoint. Additionally, you can deploy SSH certificates as long as they are already in the cloud service.
18
Deploying into a Virtual Network
Virtual Machine Settings Set Subnet on VM with Set-AzureSubnet Deployment Settings Set Virtual Network -VNetName Set DNS Servers - New-AzureDns and -DNSSettings Slide Objectives: Deploying into a Virtual Network requires multiple settings. Notes: When configuring the VM you must specify the subnet using the Set-AzureSubnet cmdlet. You can only specify the VNET and DNS settings for a cloud service on the creation of the first VM. If you add a second VM to the cloud service it will inherit the networking settings.
19
Provisioning into a VNET and Active Directory
$dom = 'contoso' $jdom = 'contoso.com' $onPremDNS = New-AzureDns -IPAddress ' ' -Name 'OnPremDNS' $cloudDNS = New-AzureDns -IPAddress ' ' -Name 'CloudDNS' $computerOU = $advmou = 'OU=AzureVMs,DC=contoso,DC=com‘ New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -WindowsDomain -Password $pwd -Domain $dom ` -DomainUserName $domUser -DomainPassword $dpwd -JoinDomain $jdom ` -MachineObjectOU 'AzureVMs' | Set-AzureSubnet -SubnetNames 'AppSubnet' | New-AzureVM –ServiceName $svc -AffinityGroup 'adag' ` -VNetName 'ADVNet' -DnsSettings $onPremDNS, $cloudDNS Slide Objectives: In this example we’re specifying two AD/DNS servers – one that lives on our on-premises environment and the other is a DC that lives in the cloud. Notes: You can pass the DNS names when calling New-AzureVM. Also required is the VNET that establishes the hybrid connectivity.
20
Virtual Machine Discovery
Retrieve Cloud Services Get-AzureService Retrieve Virtual Machines for Service Get-AzureVM -ServiceName $cloudSvcName Retrieve Status for All VMs in Subsription Get-AzureService | foreach { $_ | Get-AzureVM | ft ServiceName, Name, InstanceStatus } Slide Objectives: Show different methods of discovering virtual machines
21
Virtual Machine Storage
Data Disks Add/Remove data disks at boot or while running Create blank or attach existing disks Modify Cache Settings of OS Disk or Data Disk Modifying OS Disk while running requires reboot Slide Objectives: Explain storage options
22
Data Disk Creation New Virtual Machine Creation with Data Disk
New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd | Add-AzureDataDisk -CreateNew -DiskSizeInGB 10 -DiskLabel 'myddisk' -LUN 0 | New-AzureVM -ServiceName $cloudSvcName Add new Data Disk to existing Virtual Machine Get-AzureVM -ServiceName 'myvm1' | Add-AzureDataDisk -CreateNew -DiskSizeInGB 10 -DiskLabel 'myddisk' -LUN 1 | Update-AzureVM Slide Objectives: Show examples of configuring storage Notes: The first example creates a new VM with a 10GB disk attached. The second example gets an existing VM, adds a 10GB disk to it and updates it live.
23
Modifying Cache Settings
Set Host Caching on OS Disk During Provisioning New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd | Set-AzureOSDisk -HostCaching 'ReadOnly' | New-AzureVM -ServiceDescription $cloudSvcName Set Host Caching on Existing Data Disk in running VM Get-AzureVM -ServiceName $cloudSvcName -Name 'myvm1' | Set-AzureDataDisk -HostCaching 'ReadWrite' -LUN 0 | Update-AzureVM Slide Objectives: Explain disk caching defaults and how to modify it Notes: By default OS disks have read / write caching enabled and data disks have no caching. You can use Set-AzureOSDisk or Set-AzureDataDisk to modify these settings at run time. Set-AzureOSDisk requires a reboot.
24
Configuring Endpoints
Add Endpoints at Creation New-AzureVMConfig -Name 'myvm1' -InstanceSize 'Small' -ImageName $img | Add-AzureProvisioningConfig -Windows -Password $pwd | Add-AzureEndpoint -LocalPort 80 -PublicPort 80 -Name http -Protocol tcp | Add-AzureEndpoint -LocalPort 443 -PublicPort 443 -Name https -Protocol tcp | New-AzureVM -ServiceDescription $cloudSvcName Modify Endpoints at Runtime Get-AzureVM -ServiceName $cloudSvcName -Name 'myvm1' Add-AzureEndpoint -LocalPort 53 -PublicPort 53 -Name dns -Protocol udp | Remove-AzureEndpoint -Name https | Slide Objectives: Demonstrate how to configure network endpoints on a VM
25
Disk and Image Repository
OS Images Get-AzureVMImage # Return all Get-AzureVMImage | Where { $_.Category -eq 'Microsoft' } # Return Microsoft Get-AzureVMImage | Where { $_.Category -eq 'User' } # Return Custom Get-AzureVMImage | Where { $_.Category -eq 'Partner' } # Return Partner Images Get-AzureVMImage | Where { $_.OS -eq 'Windows' } # Return only Windows OS images Remove-AzureVMImage -ImageName 'myimg' -DeleteVHD # Delete image and storage Add-AzureVMImage -OS 'Windows' -ImageName 'MyWinImage' -MediaLocation ' # Add Existing VM Image from Storage Disks Get-AzureDisk # Return all Get-AzureDisk | Where { $_.AttachedTo -eq $null } # Return all not attached to a VM Get-AzureDisk | Where { $_.OS -eq $null } # Return only data disks Get-AzureDisk | Where { $_.OS -eq 'Windows' } # Return only Windows OS disks Remove-AzureDisk -DiskName 'mydisk' -DeleteVHD # Delete disk and storage Add-AzureDisk -OS 'Windows' -DiskName 'MyWinDisk' -MediaLocation ' # Add Existing OS Disk from Storage Add-AzureDisk -DiskName 'MyDataDisk' -MediaLocation ' # Add Existing Data Disk from Storage Microsoft, Partner and User OS Disks or Data Disks Slide Objectives: Numerous examples that show how to filer output from the disk and image repository.
26
Batch Updates to Running VMs
Remove RDP and Add New Storage Across all Web Front Ends Get-AzureVM -ServiceName $svc | Where { $_.Name -match 'wfe' } | foreach { $_ | Remove-AzureEndpoint -Name 'rdp' | Add-AzureDataDisk -CreateNew -DiskSizeInGB 10 -LUN 1 -DiskLabel 'newstorage' | Update-AzureVM } Slide Objectives: Show how you can iterate through a list of VMs (like all VMs that have a name starting with wfe and perform an update such as adding a new disk and removing an endpoint.
27
Capturing a Virtual Machine as a new Image
Capture Sys-Prepped VM into a new Image (Deletes the Source VM) Save-AzureVMImage -ServiceName $cloudSvcName -Name 'myvm1' -NewImageName 'Image Name' Slide Objectives: Show how to capture a VM
28
Virtual Network Operations
View and Set Virtual Network Configuration Get-AzureVNetConfig | Select -Expand XMLConfiguration Set-AzureVNetConfig -ConfigurationPath 'c:\Network\MyNetCFG.xml' Start and Stop Virtual Network Gateway Set-AzureVNetGateway -Disconnect -VNetName 'MyVNet' -LocalNetworkSiteName 'MySite' Set-AzureVNetGateway -Connect -VNetName 'MyVNet' View Virtual Network Status Get-AzureVNetConnection -VNetName 'MyVNet' Slide Objectives: Operations allowed from PowerShell for updating an modifying VNET Settings.
29
Summary Virtual Machine Management Disk and Image Repository
Configuring Virtual Networks Slide Objectives: Summarize presentation
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.