Activate Hyper-V Feature on Windows 10 using PowerShell DSC

Recently I got a new laptop and I am planning to configure the laptops OS the best way possible.

As I’m a big fan of PowerShell DSC I want to use PowerShell DSC for this configuration. I did use PowerShell DSC in many customer engagements with Windows Server OS. Sadly the switch to Windows 10 was not as smooth as expected.

PowerShell Execution Policy

The very first and major blocking error was the PowerShell Execution Policy. Per default the PowerShell Execution Policy on Windows 10 is set to RemoteSigned. Not every DSC Module is remote-signed. A possible solution is not pretty: Setting the execution policy to a lower level of security.

BTW: This ExecutionPolicy blocks also the Domain Join of a Windows 10 VM in Azure (see: Error: “Resource”.psm1 is not digitally signed)

WindowsFeature Resource

As part of my configuration I did want to setup Hyper-V. Windows Features can be configured by using the WindowsFeature Resource. There is just one limitation that will error during runtime: The WindowsFeature Resource does require functions, that are only available in Windows Server OS. During runtime of the configuration there will be the following error message:

“Installing roles and features using PowerShell Desired State Configuration is supported only on Server SKU’s. It is not supported on Client SKU.”

To get around this issue I created the following Script Resource:

Script Hyper-V
GetScript = {
Write-Verbose "Get current status for Microsoft-Hyper-V Feature"
$hyperVFeatureState = Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V -Online -ErrorAction SilentlyContinue
return @{
Result = $hyperVFeatureState
SetScript = {
Write-Verbose "Activating Microsoft-Hyper-V Feature"
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
TestScript = {
Write-Verbose "Test the current status for Microsoft-Hyper-V Feature"
$hyperVFeatureState = & ([ScriptBlock]::Create($GetScript))
Write-Verbose "Current status is: $($hyperVFeatureState.Result.State)"
return $hyperVFeatureState.Result.State -eq 'Enabled'


If you never heard of chocolatey head over to their website: The package manager for Windows. Chocolatey is a package manager for windows and allow you to install software from their repository very easy. The even provide a DSC Resource to automate this process even further.

Implementing the cChocoInstaller comes with a small hurdle: Make sure you have the InstallDir created before using the cChocoInstaller resource. I use a File Resource in dependency with chocolatey to avoid this glitch.




The self-healing environment – PowerShell DSC for your SharePoint Ecosystem – Recap

During my preparations for Dublin I came across many topics in the Azure Automation world I wanted to automate as well. Currently the resources “on how to do this” are limited to the Microsoft Documentations available.

I planned to on-board a newly provisioned virutal machine in place and join this server into my automation account. A process I do on a day to day basis with development environments.

I tend to trash my virtual development machines on a regular basis. This process allows me to be assured that my systems are up to the customers requirement.
This means I upload the customer specific configuration and compile the DSC prior to joining the VM.
If you do already have a configuration in place and want to reuse this, you can go to step number 3.

What is the process of on-boarding a virtual machine to an Automation Account?

0. Login in to your Azure Account


1. Upload your latest DSC configuration to Azure Automation DSC

Uploading a configuration requires you to run the following PowerShell Script.

Import-AzureRmAutomationDscConfiguration -SourcePath "<Full Path to your Configuration>"`
-ResourceGroupName "<Your Resource Group Name>" `
-AutomationAccountName "<Your Automation Account Name>" `
-Published `
-Force `

2. Compile your configuration

After an successful upload you can start the compilation of your configuration. In case the configuration requires parameters, you can ass them into the cmdlet as hashtable:

$dscCompileParameters = @{ }

Start-AzureRmAutomationDscCompilationJob -AutomationAccountName "<Your Automation Account Name >"`
-ConfigurationName "<Name of your configuration>" `
-ResourceGroupName "< Your Resource Group Name>"`
-IncrementNodeConfigurationBuild `
-Parameters $dscCompileParameters `

3. Join a VM to your Azure Automation Account – using PowerShell

Register-AzureRmAutomationDscNode -AzureVMName "<Your VM Name>" `
-ResourceGroupName "< Your Resource Group Name>" `
-AutomationAccountName "<Your Automation Account Name >" `
-RebootNodeIfNeeded $true `
-NodeConfigurationName "<Your Node Configuration Name >" `
-ConfigurationMode "ApplyAndAutocorrect" `


With these few lines of PowerShell you will be able to onboard a VM to Azure Automation and configure this machine to use a specific configuration.