Deleting Azure VM Build Guide V0.1: Sainath Kev Microsoft Mvp-Directory Services
Deleting Azure VM Build Guide V0.1: Sainath Kev Microsoft Mvp-Directory Services
Deleting Azure VM Build Guide V0.1: Sainath Kev Microsoft Mvp-Directory Services
GUIDE V0.1
SAINATH KEV
MICROSOFT MVP-DIRECTORY SERVICES
Version Summary of Changes Author Date
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
[<CommonParameters>]
PARAMETERS
-DeleteVHD
Required? false
Position? 2
Accept pipeline input? false
Parameter set name (All)
Aliases None
Dynamic? false
-Name <string>
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:
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