# Hyper-V

# S2D Force remove a drive

To verify that all drives are healthy and operational :

```
Get-PhysicalDisk
```

Get the FriendlyName of the device :

```
Get-PhysicalDisk | ft FriendlyName
```

Retire the disk :

```
Set-PhysicalDisk -FriendlyName "<DeviceName>" -Usage Retired
```

Find the name of the Virtual Disk :

```
Get-VirtualDisk
```

If the name is too long use :

```
Get-VirtualDisk | ft -AutoSize
```

For every Virtual Disk in the storage pool do :

```
Repair-VirtualDisk -FriendlyName "YourVirtualDisk"
```

Open a new PowerShell window to monitor the repairs with :

```
Get-StorageJob
```

Remove the PhysicalDisk if all repairs are successfully done:

```
Get-PhysicalDisk | Where-Object { $_.Usage -eq ‘Retired’}
```

Assign the disk to a variable:

```
$DiskToRemove = Get-PhysicalDisk | Where-Object { $_.Usage -eq ‘Retired’}
```

Find the name of the storage pool:

```
Get-StoragePool
```

Delete the physical disk from the storage pool:

```
Remove-PhysicalDisk -PhysicalDisks $DiskToRemove -StoragePoolFriendlyName "Storage pool"
```

# Add IP on vSwitch

So you installed hyper-v and you need to configure your NIC with your public IP and your secondary IP's, let me show you how.

(Would recommend having physical access / KVM IP if anything fails)

First create a v-Switch in the hyper-v settings.

[![Capture.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/scaled-840-0/Capture.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/Capture.PNG)

Then, go to the IPv4 settings of your new hyper-v vswitch and add your primary IP.

[![Capture2.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/scaled-840-0/Capture2.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/Capture2.PNG)

To add your secondary IP's, you will need to go the the advanced options and put in the first usable address of your secondary subnet, not the broadcast address but the first usable address and the subset below.

You will then use that address as the gateway for your VM's.

[![Capture3.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/scaled-840-0/Capture3.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/Capture3.PNG)

Last step will be to enable ip forwarding, open power-shell as admin and type the following commands :

```
netsh
netsh> interface ipv4
```

Then the following command to view the list of available interfaces

```
netsh interface ipv4> show int
```

To view the interface settings, replace "15" by the proper ID :

```
netsh interface ipv4> show int 15
```

And finally, the following command to enable IP forwarding :

```
netsh interface ipv4> set int 15 forwarding=enabled    
```

[![Capture4.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/scaled-840-0/Capture4.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2017-12-Dec/Capture4.PNG)

# Adding Adapter on vSwitch

List Adapter

```
Get-VMNetworkAdapterVlan -ManagementOS 
```

Adding Adapter

```
Add-VMNetworkAdapter -ManagementOS -Name "Lan" -SwitchName "vSwitch"
Add-VMNetworkAdapter -ManagementOS -Name "Wan" -SwitchName "vSwitch"
```

Tagging vlan on Adapter

```
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "LAN" -Access -VlanId 3023
Set-VMNetworkAdapterVlan -ManagementOS -VMNetworkAdapterName "Wan" -Access -VlanId 2295
```

If you need to remove an Adapter

```
Remove-VMNetworkAdapter -ManagementOs -VMNetworkAdapterName LAN
```

Add an IP to an Adapter

```
New-NetIPAddress -InterfaceAlias "vEthernet (LAN)" -IPAddress 10.10.10.10 -PrefixLength 24 -Type Unicast
New-NetIPAddress -InterfaceAlias "vEthernet (WAN)" -IPAddress 1.1.1.1 -PrefixLength 24 -DefaultGateway 2.2.2.2 -Type Unicast
```

# AVMA - Hyper-V Automatic Virtual Machine Activation

### Open CMD/Powershell

```
slui 3
```

<table id="bkmrk-guest-operating-syst" style="height: 306px;" width="677"><tbody><tr style="height: 29px;"><th style="height: 29px; width: 314px;">Guest Operating System</th><th style="height: 29px; width: 362px;">Key</th></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2012 R2 Essentials</td><td style="height: 29px; width: 362px;">K2XGM-NMBT3-2R6Q8-WF2FK-P36R2</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2012 R2 Standard</td><td style="height: 29px; width: 362px;">DBGBW-NPF86-BJVTX-K3WKJ-MTB6V</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2012 R2 Datacenter</td><td style="height: 29px; width: 362px;">Y4TGP-NPTV9-HTC2H-7MGQ3-DV4TW</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2016 Essentials</td><td style="height: 29px; width: 362px;">B4YNW-62DX9-W8V6M-82649-MHBKQ</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2016 Standard</td><td style="height: 29px; width: 362px;">C3RCX-M6NRP-6CXC9-TW2F2-4RHYD</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2016 Datacenter</td><td style="height: 29px; width: 362px;">TMJ3Y-NTRTM-FJYXT-T22BY-CWG3J</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2019 Essentials</td><td style="height: 29px; width: 362px;">2CTP7-NHT64-BP62M-FV6GG-HFV28</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2019 Standard</td><td style="height: 29px; width: 362px;">TNK62-RXVTB-4P47B-2D623-4GF74</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 314px;">Windows Server 2019 Datacenter</td><td style="height: 29px; width: 362px;">H3RNG-8C32Q-Q8FRX-6TDXV-WMBMW</td></tr></tbody></table>

### Supported Activation

<table id="bkmrk-host-windows-server-" style="height: 232px; width: 874px;"><tbody><tr style="height: 33px;"><td style="height: 33px; width: 295px;">**Host**</td><td style="height: 33px; width: 284px;">**Windows Server 2012 R2 will activate**

</td><td style="height: 33px; width: 295px;">**Windows Server 2016 will activate**

</td></tr><tr style="height: 35px;"><td style="height: 35px; width: 295px;">Windows Server 2012 R2 Essentials Edition&gt;</td><td style="height: 35px; width: 284px;"><span style="color: #339966;">Yes</span>

</td><td style="height: 35px; width: 295px;"><span style="color: #339966;">Yes</span>

</td></tr><tr style="height: 35px;"><td style="height: 35px; width: 295px;">Windows Server 2012 R2 Standard Edition</td><td style="height: 35px; width: 284px;"><span style="color: #339966;">Yes</span>

</td><td style="height: 35px; width: 295px;"><span style="color: #339966;">Yes</span>

</td></tr><tr style="height: 31px;"><td style="height: 31px; width: 295px;">Windows Server 2012 R2 Datacenter Edition</td><td style="height: 31px; width: 284px;"><span style="color: #339966;">Yes</span>

</td><td style="height: 31px; width: 295px;"><span style="color: #339966;">Yes</span>

</td></tr><tr style="height: 29px;"><td style="height: 29px; width: 295px;">Windows Server 2016 Essentials Edition</td><td style="height: 29px; width: 284px;"><span style="color: #ff0000;">No</span>

</td><td style="height: 29px; width: 295px;"><span style="color: #339966;">Yes</span>

</td></tr><tr style="height: 36px;"><td style="height: 36px; width: 295px;">Windows Server 2016 Standard Edition</td><td style="height: 36px; width: 284px;"><span style="color: #ff0000;">No</span>

</td><td style="height: 36px; width: 295px;"><span style="color: #339966;">Yes</span>

</td></tr><tr style="height: 33px;"><td style="height: 33px; width: 295px;">Windows Server 2016 Datacenter Edition</td><td style="height: 33px; width: 284px;"><span style="color: #ff0000;">No</span>

</td><td style="height: 33px; width: 295px;"><span style="color: #339966;">Yes</span>

</td></tr></tbody></table>

<table id="bkmrk-server-host-version-"><thead><tr><th>Server host version</th><th>Windows Server 2019</th><th>Windows Server 2016</th><th>Windows Server 2012 R2</th></tr></thead><tbody><tr><td>Windows Server 2019</td><td>X</td><td>X</td><td>X</td></tr><tr><td>Windows Server 2016</td><td aria-label="No value"> </td><td>X</td><td>X</td></tr><tr><td>Windows Server 2012 R2</td><td aria-label="No value"> </td><td aria-label="No value"> </td><td>X</td></tr></tbody></table>

# Configuring DR Replica

<div data-id="1533674335445_503484042" data-pageid="54503716" id="bkmrk-open-failover-cluste"><div data-id="1533674335445_503484042" data-pageid="54503716"><div><div><form class="aui tf-form" name="inlinecommentform"><div>Open failover cluster manager</div><div></div><div>Right click the Cluster -&gt; Select "Configure Role"</div><div>   
Click next -&gt; select Hyper-V Replica Broker</div><div></div></form></div></div></div></div><div data-id="1533674335445_503484042" data-pageid="54503716" id="bkmrk-%C2%A0"><div data-id="1533674335445_503484042" data-pageid="54503716"><div><div><div><div>[![Configure-Role.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/scaled-840-0/Configure-Role.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/Configure-Role.PNG) </div><div></div></div></div></div></div></div>Fill in the information (Choose an available IP from his subnet)

[![configrole2.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/scaled-840-0/configrole2.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/configrole2.PNG)

**Create SSL cert via Powershell**

For this, you will need to download Windows SDK and install

[https://msdn.microsoft.com/library/windows/desktop/aa386968.aspx](https://msdn.microsoft.com/library/windows/desktop/aa386968.aspx)

#### Create the ROOT certificate

<div id="bkmrk-%26-%22c%3A%5Cprogram-files%5C"><div><div>```
& "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64\makecert.exe" -pe -n “CN=PrimaryRootCA” -ss root -sr LocalMachine -sky signature -r “PrimaryRootCA.cer”
```

</div></div></div>#### Create SSL with the hostname of DR 

```
& "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64\makecert.exe" -pe -n “CN=dr.domain.com” -ss my -sr LocalMachine -sky exchange -eku "1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2" -in “primaryRootCA” -is root -ir LocalMachine -sp “Microsoft RSA SChannel Cryptographic Provider” -sy 12 replicaCert.cer
```

<div id="bkmrk--0"><div><div><div></div></div></div></div>#### Create SSL with the name of the Hyper-V Replica Broker you created

Note, if you are in an AD, you will need to add the full FQDN of the broker

```
& "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\x64\makecert.exe" -pe -n “CN=HyperV-Broker.domain.com” -ss my -sr LocalMachine -sky exchange -eku "1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2" -in “primaryRootCA” -is root -ir LocalMachine -sp “Microsoft RSA SChannel Cryptographic Provider” -sy 12 primaryCert.cer
```

<div id="bkmrk--1"><div><div><div></div></div></div></div>### On all hosts (nodes and DR) disable SSL revocation

```
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Replication" /v DisableCertRevocationCheck /d 1 /t REG_DWORD /f
```

<div id="bkmrk--2"><div><div><div></div></div></div></div>#  **Exporting the SSL**

Open Certificate MMC console (simply search for certificate and click on "Manage Computer Certificates")

Under personal, click certificates

Right click ethe DR certificate -&gt; all task -&gt; export

[![export-ssl-with-private-key1.PNG](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/scaled-840-0/export-ssl-with-private-key1.PNG)](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/export-ssl-with-private-key1.PNG)

Click Next -&gt; Select "Yes, export the private key"

Click Next -&gt; Select "Password" and enter any password

Click Next -&gt; Select where to save the certificate

# **Import the SSL ceritificate**

The following steps have to be performed on the DR

Open Certificate MMC console with the snap-in to manage certs

Right click "Personal" -&gt; Select "All Task" -&gt; Select "Import"

Click Next (Local Machine) -&gt; Browse the Certificate and import

Enter the password used during the export

Click Next -&gt; Select "Place all certificates in the following store"

Click Next -&gt; Click Finish

Once done, move the Root Certificate under "Certificates" of "Trusted Root Certificate Authorities"

<div id="bkmrk--4"></div># **Configure the Replication Role in Hyper-V**

In Hyper-V, right click the server -&gt; Click on "Hyper-V Settings"

Select the "Replication Configuration" tab

Click "Enable this computer as Replica Server" -&gt; Click "Use certificate-based authentication (HTTPS)" -&gt; Select the Certificate

Under "Authorization and storage" -&gt; Select "Allow replication from any authenticated server" with default value (C:\\Users\\Public\\Documents\\Hyper-V\\Virtual Hard Disks)

[![screenshot_4.png](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/scaled-840-0/screenshot_4.png)](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/screenshot_4.png)

<div id="bkmrk--6"></div># Enabling Replication for VM

  
Right click on the VM and select "Enable Replication"

[![htAscreenshot_3.png](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/scaled-840-0/htAscreenshot_3.png)](https://wiki.myhypervisor.ca/uploads/images/gallery/2018-08-Aug/htAscreenshot_3.png)

Click Next -&gt; Enter the hostname (that we put in the host file earlier)

Once it loads (can take a minute or 2), same thing as with the DR, select "Use certificate-based authentication (HTTPS)" and

select the certificate (make sure "Compress the data that is transmitted over the network"

Keep clicking next a select the options you want for the replication

## Server 2016

Server 2016 is the same concept but you will need to create a cert for all nodes

**Create root CA**

```
New-SelfSignedCertificate `
-DnsName “HyperVReplicationRootCA” `
-CertStoreLocation Cert:\LocalMachine\My `
-KeyLength “4096" `
-Hash SHA256 `
-KeyFriendlyName “HyperVReplicationRootCA” `
-FriendlyName “HyperVReplicationRootCA” `
-NotAfter “2030-12-31 23:59:59” `
-NotBefore “2018-10-10 00:00:00" `
-KeyUsage CertSign,CRLSign,DigitalSignature
```

**Create node cert ( 1 cert per node)**

```
New-SelfSignedCertificate `
-DnsName Myfqdn.domain.com `
-CertStoreLocation Cert:\LocalMachine\My `
-KeyLength “4096" `
-Hash SHA256 `
-KeyFriendlyName hostname `
-FriendlyName hostname `
-NotBefore “2017-01-01 00:00:00" `
-NotAfter “2030-12-31 23:59:59” `
-Signer ( Get-ChildItem Cert:\LocalMachine\My | Where -Prop Subject -eq "CN=HyperVReplicationRootCA" )
```

Use same command for broker cert and export / import cert on all nodes / dr server as explained above