Sunteți pe pagina 1din 6

DELETING AZURE VM BUILD

GUIDE V0.1

SAINATH KEV
MICROSOFT MVP-DIRECTORY SERVICES
Version Summary of Changes Author Date

0.1 Document Creation Sainath 9/08/2015


1. Introduction
This article explains the steps involved in deleting an Azure VM using PowerShell cmdlets.
Azure VM can be deleted using GUI or PowerShell with appropriate permissions on the
cloud service and subscription.

2. Environment Requirements
Below are the environment requirements for performing deletion of Azure VM.

Component Details
Azure Subscription and Account  Required
requirements  Service Administrator / Co-Administrator
permissions required
Windows PowerShell  Version 4.0 with Web Platform installer
installed and configured
 Microsoft Azure PowerShell Module
installed and configured
Azure VMs Preconfigured
Script execution Set-ExecutionPolicy RemoteSigned
Table 1: Environment Setup Requirements

3. Remove-AzureVM Cmdlet
The cmdlet will delete Azure VM. The syntax of the cmdlet is shown below (Note: please
refer the MSDN documentation for updated details)
PS C:\> get-help remove-azurevm -Full

NAME

Remove-AzureVM

SYNTAX

Remove-AzureVM [-ServiceName] <string> [-Name] <string> [[-DeleteVHD]] [-Profile <AzureProfi

[<CommonParameters>]

PARAMETERS

-DeleteVHD

Specify to remove the VM and the underlying disk blob(s).

Required? false
Position? 2
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
-Name <string>

The name of the role to remove.

Required? true
Position? 1
Accept pipeline input? true (ByPropertyName)
Parameter set name (All)
Aliases None
Dynamic? false
-Profile <AzureProfile>
In-memory profile.
Required? false
Position? Named
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
-ServiceName <string>
Service name.
Required? true
Position? 0
Accept pipeline input? true (ByPropertyName)
Parameter set name (All)
Aliases None
Dynamic? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.String
OUTPUTS
Microsoft.WindowsAzure.Commands.Utilities.Common.ManagementOperationContext
ALIASES
None
REMARKS
None

4. Execution Steps
Following are the steps required to delete a VM using PowerShell

Task Action
Preparing Environment
Step1: How https://msdn.microsoft.com/en-us/library/dn385850(v=nav.70).aspx
to: Download
and Import
Publish
Settings and
Subscription
Information
Step2: Run
Get-
AzureSubscrip
tion to view
your
subscriptions For selecting Azure Subscription run the below commands
and select the Select-AzureSubscription –current and provide SubscriptionName
subscription
to perform
the action
Eg:

To check which subscription is set to current, run the below command

Connecting
Connecting Before deleting specific VM / set of VMs, identify the Azure Service associated
Azure Cloud with VM
Service I have created 4 subscriptions in my test lab

Or

View VMs
configured in
a cloud
service
Stop VM If VM is not in stop state, run below command to stop the VM
“Stop-AzureVM –ServiceName ‘<EnterServiceName>’ –StayProvisioned –Name
‘<VMName>’
To turn off list of VM’s use PowerShell loop using the below link
http://blogs.technet.com/b/parallel_universe_-
_ms_tech_blog/archive/2013/12/16/stop-amp-start-your-vm-s-on-azure-with-
powershell.aspx
Delete VM Remove-AzureVM –ServiceName ‘<servicename>’ –Name ‘<VM Name> -
DeleteVHD
Confirm To Confirm VM Deletion:
Deletion of Get-AzureVM –Servicename ‘<servicename>’
VM and Data The above command will not display the deleted VM name
Disk
To Confirm VM disk deletion
Get-AzureDisk | Where-object {$_.AttachedTo.Rolename –eq ‘<VMName>’}
The above command will return null