TechShizz | Tech Guides

Configure a Storage Replica | Server 2016

The below PowerShell commands can be used to configure a Storage Replica.

# install storage replica feature on replication partners
Invoke-Command -ComputerName FS1,FS2 -ScriptBlock { Install-WindowsFeature -Name Storage-Replica,FS-FileServer -IncludeManagementTools -Restart }

# test out a potential partnership
Test-SRTopology -SourceComputerName FS1 -SourceVolumeName R: -SourceLogVolumeName L: `
                -DestinationComputerName FS2 -DestinationVolumeName R: -DestinationLogVolumeName L: `
                -DurationInMinutes 1 -ResultPath c:\logs -IgnorePerfTests

# create a storage replica partnership
New-SRPartnership -SourceComputerName FS1 -SourceRGName FS1RG -SourceVolumeName R: -SourceLogVolumeName L: `
                  -DestinationComputerName FS2 -DestinationRGName FS2RG -DestinationVolumeName R: -DestinationLogVolumeName L:

# view replication status
(Get-SRGroup).Replicas
Get-WinEvent -ProviderName Microsoft-Windows-StorageReplica

# add some files to the source volume
"Hello!" > r:\file.txt
"Was it me," > r:\file2.txt
"you were looking for?" > r:\file3.txt
fsutil file createnew r:\file4.dat 1000000000

# reverse replication
Set-SRPartnership -NewSourceComputerName FS2 -SourceRGName FS2RG -DestinationComputerName FS1 -DestinationRGName FS1RG

# remove replication and clean up
Get-SRPartnership | Remove-SRPartnership

Invoke-Command -ComputerName FS1,FS2 -ScriptBlock {
    Get-SRGroup | Remove-SRGroup
}



Create Storage Pools, Virtual Disks and Volumes with Server Manager in Server 2012 / 2016

Here are the PowerShell Commands to complete:

# create a new storage pool
New-StoragePool -FriendlyName AllTheDisks -StorageSubSystemUniqueId (Get-StorageSubSystem).UniqueId -PhysicalDisks (Get-PhysicalDisk -CanPool $true)

# create virtual disk
New-VirtualDisk -FriendlyName CompanyData -StoragePoolFriendlyName AllTheDisks -Size 2TB -ProvisioningType Thin -ResiliencySettingName Mirror

# initialize underlying physical disks
Initialize-Disk -VirtualDisk (Get-VirtualDisk -FriendlyName CompanyData)

# partition and format volumes from virtual disk
$vd = Get-VirtualDisk -FriendlyName CompanyData | Get-Disk

$vd | 
    New-Partition -Size 100GB -Driveletter U |
            Format-Volume -FileSystem NTFS -AllocationUnitSize 4096 -NewFileSystemLabel "User Data"

$vd |     
    New-Partition -Size 500GB -Driveletter I |
        Format-Volume -FileSystem ReFS -AllocationUnitSize 4096 -NewFileSystemLabel "IT Data"

$vd | 
    New-Partition -Size 1TB -Driveletter V |
        Format-Volume -FileSystem ReFS -AllocationUnitSize 65536 -NewFileSystemLabel "VM Data"

 

Using DISM to Add Drivers / Packages / Install Roles and Features in a .wim file

The following reference folders that contain the relevent drivers/packages. Ensure you have the driver/package in the right location e.g. .\drivers

### DISM - Deployment Image Servicing and Management Command-line Utility ###

## Desktop Experience & Server Core ##

# display help
dism /?

# view images within a .wim
dism /get-imageinfo /imagefile:.\images\install.wim

# mount server core datacenter image
dism /mount-image /imagefile:.\images\install.wim /index:3 /mountdir:.\mount

# add drivers (.inf)
dism /image:.\mount /get-drivers
dism /image:.\mount /add-driver /driver:.\drivers
dism /image:.\mount /remove-driver /driver:.\drivers\iaStorAC.inf

# add patches, hotfixes, and updates (.msu or .cab)
dism /image:.\mount /get-packages
dism /image:.\mount /add-package /packagepath:.\updates
dism /image:.\mount /remove-package /packagepath:.\updates\windows10.0-kb3150513.msu

# install roles and features
dism /image:.\mount /get-features
dism /image:.\mount /get-featureinfo /featurename:web-server
dism /image:.\mount /enable-feature /featurename:web-server /all
dism /image:.\mount /disable-feature /featurename:web-server

# dismount and commit all changes
dism /unmount-image /mountdir:.\mount /commit


## Nano Server ##

# view nano server images
dism /get-imageinfo /imagefile:.\images\nanoserver.wim

# mount nano server datacenter image
dism /mount-image /imagefile:.\images\nanoserver.wim /index:2 /mountdir:.\mount

# add nano server package
dism /image:.\mount /add-package /package:d:\nanoserver\packages\microsoft-nanoserver-containers-package.cab

# dismount and commit all changes
dism /unmount-image /mountdir:.\mount /discard

 

Using PowerShell to Add Drivers / Packages / Install Roles and Features in a .wim file

The following reference folders that contain the relevent drivers/packages. Ensure you have the driver/package in the right location e.g. .\drivers

### DISM - Deployment Image Servicing and Management PowerShell Cmdlets ###

## .wim ##

# view cmdlets in DISM module
Get-Command -Module DISM

# view images within a .wim
Get-WindowsImage -ImagePath .\images\install.wim
Get-WindowsImage -ImagePath .\images\nanoserver.wim

# mount server core datacenter image
Mount-WindowsImage -ImagePath .\images\install.wim -Path .\mount -Index 3

# add drivers (.inf)
Get-WindowsDriver -Path .\mount
Add-WindowsDriver -Path .\mount -Driver .\drivers\iaStorAC.inf

# add packages (.msu or .cab)
Get-WindowsPackage -Path .\mount
Add-WindowsPackage -Path .\mount -PackagePath .\updates\windows10.0-kb3150513.msu

# install roles and features
Get-WindowsOptionalFeature -Path .\mount -FeatureName dhcpserver
Enable-WindowsOptionalFeature -Path .\mount -FeatureName dhcpserver
Disable-WindowsOptionalFeature -Path .\mount -FeatureName dhcpserver

# dismount and commit changes
Dismount-WindowsImage -Path .\mount -Save


## .vhd/vhdx ##

# mount nano server datacenter vhd
Mount-WindowsImage -ImagePath .\image\nanoserver.wim -Path .\mount -Index 2

# add iis package
Add-WindowsPackage -Path .\mount -PackagePath d:\nanoserver\packages\microsoft-nanoserver-iis-package.cab

# dismount and commit changes
Dismount-WindowsImage -Path .\mount -Save

 

 

Connecting to and Configuring Nano Servers

Before we can connect to a Nano server we need to add it to the trusted hosts list of the server you are connecting from.

Set-Item WSMan:\localhost\Client\TrustedHosts "192.168.1.100"

Then to create a new session to the server

$nano - New-PSSession -ComputerName 192.168.1.100 -Credential (Get-Credential)

Next, to join the Nano server to the Domain we need to use the Offline domain join method to create a blob file. This command should be run on the DC, so Exit-PSSession from the session above if still connected.

djoin.exe /provision /domain testlab.local /machine NanoServer1 /savefile .\djoin.blob

Next we need to copy this blob file to the C:\ on the NanoServer1. We can pass this file right into the session variable we made earlier.

Copy-Item -Path .\djoin.blob -DestinationPath C:\ -Tosession $nano

Next we connect back to the nano server to complete the join.

Enter-PSSession -Session $nano

Next we need to complete the join using the blob file on the NanoServer1.

djoin.exe /requestodj /loadfile C:\djoin.blob /windowspath C:\windows /localos

Once complete just reboot the nano server - You should then be able to log onto it with the domain administrator credentials.

Its also good practice to remove the IP from the trusted hosts list that we added earlier like this. 

Set-Item WSMan:\localhost\Client\TrustedHosts ""

Now that the NanoServer1 is a member of the domain, we can now run a remote powershell session to it via it's DNS name like this, and if we're logged in with adminsitrative credentials we dont even need to add the Get-Credential cmdlet.

Enter-PSSession -ComputerName NanoServer1

Installing Packages

To see a list of all Package Providers. These are online repositories that PowerShell can download packages from.

Find-PackageProvider

To find what packages a particular provider has run

Find-Package -ProviderName NanoServerPackage

where "nanoserverpackage" is the name of the desired package provider.

Next we need to install the package provider top use it.

Install-PackageProvider NanoServerPackage

Once installed we need to Import the Package Provider, like importing a module but it's a different command. 

Import-PackageProvider NanoServerPackage

Next in this example we want to install the storage package. Using the above commands to find this we should be able to run

Install-Package -Name Microsoft-NanoServer-Storage-Package

A reboot will be required.

Once rebooted we can connect to and manage this Nano server from Server Manager simply by adding it like any other server.