< Back

Remove-AzureV2VMandResources

Tue Jan 14, 2020 12:38 am

NAME Remove-AzureV2VMandResources



SYNOPSIS

Ever feel it????????????s a pain to clear resources of a test virtual machine azure, worry no more.





SYNTAX

Remove-AzureV2VMandResources -SubscriptionId <Object> -rgName <Object> -vmNames <Object> [-DeleteDisks]

[-DeleteVNet] [-DeleteStorageAccount] [-DeleteRG] [<CommonParameters>]



Remove-AzureV2VMandResources -SubscriptionId <Object> -rgName <Object> -vmNames <Object> [-DeleteAll]

[<CommonParameters>]





DESCRIPTION

This cmdlet deletes resources unique to a virtual machine. The cmdlet will delete a machine and all its resource

i.e. Public IP, Network Interface, Virtual Machine and Disks. It will not delete any resource that can be a shared

resource e.g. Virtual Network, Network Security Groups, or storage account.





PARAMETERS

-SubscriptionId <Object>

Subscription ID for the subscription that virtual machine is on



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-rgName <Object>

The Resource Group the virtual machine belongs to. Required



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-vmNames <Object>

The name or names of the virtual machine(s) to be deleted. Required



Required? true

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-DeleteDisks [<SwitchParameter>]

When switch is present, cmdlet will delete disk attached to virtual machine. DELETING OF DISK MEANS THERE IS A

POTENTIAL FOR DATA LOSS, USE AT YOUR OWN RISK.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-DeleteVNet [<SwitchParameter>]

When switch is present, cmdlet will try to delete VNet the virtual machine was attached to, VNet will not be

deleted if it is in use by other Virtual machines.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-DeleteStorageAccount [<SwitchParameter>]

When switch is present, cmdlet will try to delete Storage Account the virtual machine was attached to, Storage

Account will not be deleted if it contains VHDs. DELETING OF STORAGE ACCOUNT MEANS THERE IS A POTENTIAL FOR

DATA LOSS, USE AT YOUR OWN RISK.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-DeleteRG [<SwitchParameter>]

When switch is present, cmdlet will try to delete Resource group the virtual machine was attached to, Resource

group will not be deleted if it is in use by other Resources.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-DeleteAll [<SwitchParameter>]

When switch is present, All the delete Switch will be enabled.



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



NOTES





Author : Hannel Hazeley - hhazeley@outlook.com



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Remove-AzureV2VMandResources -SubscriptionId "1d6737e7-4f6c-4e3c-8cd4-996b6f003d0e" -rgName DVideoRG1

-vmNames DV1-DPBSV1-002 -DeleteDisks



This will delete virtual machine and all resources including OS and data disks attached to virtual machine









-------------------------- EXAMPLE 2 --------------------------



PS C:\\>Remove-AzureV2VMandResources -SubscriptionId "1d6737e7-4f6c-4e3c-8cd4-996b6f003d0e" -rgName DVideoRG1

-vmNames DV1-DPBSV1-002



This will delete virtual machine and all resources excluding OS and data disks attached to virtual machine









-------------------------- EXAMPLE 3 --------------------------



PS C:\\>Remove-AzureV2VMandResources -SubscriptionId "1d6737e7-4f6c-4e3c-8cd4-996b6f003d0e" -rgName DVideoRG1

-vmNames "DV1-DPBSV1-001","DV1-DPBSV1-002"



This will delete both virtual machines and all resources excluding their OS and data disks attached to virtual

machines











RELATED LINKS

https://github.com/hhazeley/HannelsTool ... ources.ps1