< Back

New-AzVMClone

Sat Jan 11, 2020 8:33 am

NAME New-AzVMClone



SYNOPSIS

From an existing Virtual Machine, clone its configuration and change it's Availability Set

affiliation (migrate, remove, leave 'as-is')





SYNTAX

New-AzVMClone [-VMObject] <Object> [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]



New-AzVMClone [-VMObject] <Object> [-AvailabilitySetName] <String> [-MigrateAvailabilitySet] [[-Resize]] [-Force]

[-WhatIf] [-Confirm] [<CommonParameters>]



New-AzVMClone [-VMObject] <Object> [-RemoveAvailabilitySet] [[-Resize]] [-Force] [-WhatIf] [-Confirm]

[<CommonParameters>]





DESCRIPTION

This function is designed to MIGRATE or REMOVE an Azure Virtual Machine to or from an

Availability Set. This function requires that the incoming object, through pipeline

or parameter, is a Virtual Machine object. Most commonly, this object is created

using the Get-AzVM cmdlet and storing the VM(s) into a variable.



This function assumes that IF you are migrating a Virutal Machine to NEW Availability

Set, the target Availability Set has already been created.



WARNING: THIS FUNCTION DOES NOT CURRENTLY ADDRESS ANY EXTENSION FOR THE VIRTUAL MACHINE

AND THEY WILL NEED TO BE RE-INSTALLED MANUALLY.





PARAMETERS

-VMObject <Object>

The VM Object(s) to be cloned



Required? true

Position? 1

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



-AvailabilitySetName <String>

The name of the new Availability Set to associated with the cloned VM(s)



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-MigrateAvailabilitySet [<SwitchParameter>]

Switch to enable Availability Set migration



Required? true

Position? 1

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-RemoveAvailabilitySet [<SwitchParameter>]

Switch to remove a VM from its current availability set after cloning



Required? true

Position? 1

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Resize [<SwitchParameter>]

Switch to resize the VM to a new size



Required? false

Position? 3

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-Force [<SwitchParameter>]

Switch parameter to bypass confirmation



Required? false

Position? named

Default value False

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

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

Microsoft.Azure.Commands.Compute.Models.PSVirtualMachine



Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineList





OUTPUTS

None. This function does not provide an output, only on screen information





CHANGE LOG

---------------------------------------------------------------------------------

v1.2

- Primary production release

v1.3

- Fixed some string values that called a split method, but if the value was NULL, the method would error.

Changed to an operator.

v1.4

- Fixed issue where grabbing the string from the StorageUri would incorrectly split the string

- Moved the Show-Menu helper function inside the main function

v1.5

- Added support for VM Resize during clone operation (new function Select-AzVMSize)

- Added support for VM(s) that are using a Marketplace plan

- Added feature where the VMObject is converted to JSON (in the same working directory) before it is deleted

from Azure

v1.6

- Fix display output for Resize and plan properties cloning





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



PS C:\\>Get-AzVM -ResourceGroupName MyResourceGroup -Name TestVM001 | New-AzVMClone -MigrateAvailabilitySet

-AvailabilitySetName MyNewAS01



- OR -



PS C:\\>$myVM = Get-AzVM -ResourceGroupName MyResourceGroup -Name TestVM001

PS C:\\>$myVM | New-AzVMClone -MigrateAvailabilitySet -AvailabilitySetName MyNewAS01



- OR -



PS C:\\>$myVM = Get-AzVM -ResourceGroupName MyResourceGroup -Name TestVM001

PS C:\\>New-AzVMClone -VMObject $myVM -MigrateAvailabilitySet -AvailabilitySetName MyNewAS01



Description: Migrate a single Virtual Machine to a new Availability Set









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



PS C:\\>Get-AzVM -ResourceGroupName MyResourceGroup -Name TestVM001 | New-AzVMClone -RemoveAvailabilitySet



- OR -



PS C:\\>$myVM = Get-AzVM -ResourceGroupName MyResourceGroup -Name TestVM001

PS C:\\>$myVM | New-AzVMClone -RemoveAvailabilitySet



- OR -



PS C:\\>$myVM = Get-AzVM -ResourceGroupName MyResourceGroup -Name TestVM001

PS C:\\>New-AzVMClone -VMObject $myVM -RemoveAvailabilitySet



Description: Remove a single Virtual Machine from an Availability Set









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



PS C:\\>Get-AzVM -ResourceGroupName MyResourceGroup | New-AzVMClone -MigrateAvailabilitySet -AvailabilitySetName

MyNewAS01



- OR -



PS C:\\>$myVMs = Get-AzVM -ResourceGroupName MyResourceGroup

PS C:\\>$myVMs | New-AzVMClone -MigrateAvailabilitySet -AvailabilitySetName MyNewAS01



- OR -



PS C:\\>$myVMs = Get-AzVM -ResourceGroupName MyResourceGroup

PS C:\\>New-AzVMClone -VMObject $myVMs -MigrateAvailabilitySet -AvailabilitySetName MyNewAS01



Description: Migrate a GROUP of Virtual Machines in a Resource Group to a new Availability Set









-------------------------- EXAMPLE 4 --------------------------



PS C:\\>Get-AzVM -ResourceGroupName MyResourceGroup | New-AzVMClone -RemoveAvailabilitySet



- OR -



PS C:\\>$myVMs = Get-AzVM -ResourceGroupName MyResourceGroup

PS C:\\>$myVMs | New-AzVMClone -RemoveAvailabilitySet



- OR -



PS C:\\>$myVMs = Get-AzVM -ResourceGroupName MyResourceGroup

PS C:\\>New-AzVMClone -VMObject $myVMs -RemoveAvailabilitySet



Description: Remove a GROUP of Virtual Machines in a Resource Group from an Availability Set











RELATED LINKS