PowerShell Virtual Machine Replication Using Hyper-V Replica #cloud #scvmm #Microsoft

As we Created a VM in SCVMM and this VM is placed on a cluster I want to Replicate this to an other Hyper-v Cluster just for DR.

The Script can be found here Enable Replication VM for Hyper-v Cluster



First we set the Variables

# Variable
$SourceHV= "MVPTENANT001"

The fist stepes are just checking if you already have a VM that is replicated and if there are any errors.

# Replica info
Get-Command –Module Hyper-V *repl*

# get current status

#get repl server status settings
Get-VMReplication –ReplicaServerName $ReplHV

#get ReplicationHealth status
Get-VMReplication –ReplicationHealth Normal
Get-VMReplication –ReplicationHealth Warning

#get repl server
Get-VMReplicationServer $ReplHV
Get-VMReplication -ComputerName $SourceHV | Format-List *

(1..2) | % {get-VMReplicationServer –ComputerName MVPTENANT01$_} | Format-Table repenabled, authtype, intauth, certauth, anyserver, moninterval, monstarttime, computername




Now that we have checked that the Replication is Configured we can start creating the Replication

enable-VMReplication –VMname $DRVM –ReplicaServerName $ReplHV –ReplicaServerPort 80 -AuthenticationType Kerberos


when Checking the Replication Settings in the cluster we can see the replication is enabled. Now we can start the replication

#start init Replication
Start-VMInitialReplication –VMName $DRVM

to see if the replication is started we do some checking

#show status
Get-VMReplication | Format-List *


After the initial replication it will follow the default replication schedule.



As these are just simple steps you can expand this to a bigger volume.

Happy clustering

Robert Smit



PowerShell Creating and Deploying Virtual Machines in VMM for Azure Pack #wapack #cloud #scvmm #Microsoft

Now that More and more customers are using SCVMM and with Clustering. I decided that I should post some helpful easy PowerShell scripts.

Ok I’m no Posh MVP the scripts are working and will get you started with things.

The First script I post is a Create a Virtual Machine with Powershell Based on a VHDX that is also used for VMM.

The Script can be found here  “Powershell Script to Create Hyper VM and copy syspreped VHDX to CSV “ it is still a GEN 1 VM!



First we do set some variables for the script

# Variable
$SMBShare= "SMBVM01"
$CPU= 2
$mem= 4GB
$HVcluster= "MVPTENANT001"
$VlanID= 1234
$HVswitch="Tenant Switch"

Next step is create a new VM and place this on the SMB share

# Create New VM
New-VM -Path \\MVPSofs001\$SMBShare\ -Name $vm -Generation 1 -newVHDPath "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$VM.VHDX" -NewVHDSizeBytes 5GB -SwitchName $HVswitch -Memory 4GB

As the Disk is just a place holder and will be replaced by my template.

#VM adjustments Dynamic or Fixed
# Set-VM -Name $vm -DynamicMemory -MemoryMaximumBytes 4GB -MemoryMinimumBytes 4GB -MemoryStartupBytes 4GB -ProcessorCount 2
Set-VM -Name $vm -StaticMemory -MemoryStartupBytes "$mem" -ProcessorCount "$CPU"

Set a Vlan if needed else use the #

# Set VLAN
Set-VMNetworkAdapterVlan –VMName $vm -Access –VlanId $vlanid

Now that the VM is in place and connected I’ll replace the placeholder disk and use my own syspreped disk. from the SCVMM library

# Copy Template Disk
Copy-Item -Path "\\MVPSofs001\VMMLibrary\Templates\2012R2RU2.*" -Container -Destination "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm _Disk_C.vhdx" -Recurse

# Remove Old Disk
Remove-VMHardDiskDrive -VMName $vm -ControllerType IDE -ControllerLocation 0 -ControllerNumber 0

# Add syspreped disk
Add-VMHardDiskDrive -VMName $vm -path "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm _Disk_C.vhdx" -ControllerType IDE -ControllerLocation 0 -ControllerNumber 0

Or if you need More harddisks use this

# Add-VMHardDiskDrive -VMName $vm -path "\\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm _Disk_D.vhdx" -ControllerType SCSI

# Delete Old Disk
Remove-Item -Path \\MVPSofs001\$SMBShare\$vm\Virtual Hard Disks\$vm.vhdx

#Add VM TO Cluster
Get-VM $vm | Add-VMToCluster -Cluster $HVcluster
Start-VM $vm

Easy Step by Step with a HA VM

Happy clustering

Robert Smit