Install Hyper-V on Windows 11 With PowerShell DSC

PowerShell DSC, or Desired State Configuration, is a PowerShell module that allows you to configure and manage your servers in a declarative way. This blog post will show you how to use PowerShell DSC to install Hyper-V on Windows 11.

One of the great benefits of DSC is that it can be used to define configurations for both Windows and non-Windows devices. One of the most popular examples of this is managing IIS hosting websites using DSC on a Linux server, with site definitions being stored in configuration files such as web.config or applicationHost.config rather than XML schema files which are managed by WAP (Windows Application Platform), the IIS application hosting framework for Windows servers.

Run DSC

If you are new to PowerShell DSC, follow the steps below to install Hyper-V using DSC.

Start with creating a DSC folder, and inside the folder, create a PowerShell script (.PS1) with the code below.


Configuration hyperv {
Import-DscResource -ModuleName PSDscResources

   node 'localhost' {   
        WindowsOptionalFeature hyperv {
                Name =  "Microsoft-Hyper-V-All"
                Ensure = "Present"
          }
    
    }
 
}

hyperv

Once the file is saved, Open PowerShell and open the file’s path.

Run the script using dot source as shown below.


. .\script.ps1

The above action will create a folder called hyperv with a file called localhost.mof

To test the configuration, run the following command.

Test-DscConfiguration -Path .\hyperv\

To install Hyper-V run.

Start-DscConfiguration -Path .\hyperv\ -force

To check that the configuration has been completed successfully, check the status with the cmdlet below.

Get-DscConfigurationStatus

Please visit the following category page and posts for more blog posts on the topic.


by