How do you install Hyper V on Azure Dev Ops pipeline? - azure-devops

I am trying to install Hyper V for an Azure Dev Ops (ADO) pipeline (using powershell task). When I do a "Get-VM", I am getting the typical powershell error "... not recognized as the name cmdlet" error so it make me believe Hyper V is not installed. When I do a "Get-Module -listavailable" Hyper V is not listed.
I have a build agent with Windows 2019 and Windows 2022 and neither seems to work.
I have tried the following;
DISM /Online /NoRestart /Enable-Feature /All /FeatureName:Microsoft-Hyper-V /LogLevel:4 <-- seems to work but at the end of the task it just says Exit 1
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -NoRestart -All
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Offline -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Online -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-Clients -NoRestart
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Management-PowerShell -NoRestart -All
import-module Hyper-V <-- says can't find module
I am stuck on what to do. I need Hyper V as part of my pipeline tests.
Thanks
Darren

I am afraid that Hyper V can't be enabled on Microsoft Hosted Agents. According to the documentation
Microsoft-hosted agents:
Run on Microsoft Azure general purpose virtual machines Standard_DS2_v2
Hyper V can only be enabled on Virtual Machines which supports Nested Virtualization. Check this link for more details:
https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/user-guide/nested-virtualization
Unfortunately, DSv2-series do not support Nested Virtualization

Figured it out somewhat. Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All is sufficient to do it BUT a reboot is needed which is a new issue. Will follow up with that in a separate posting.

Related

JFROG pipelines Windows static node throws "check_win_containers_enabled : Windows Containers must be enabled" error on adding

When adding a windows static node on jfrog pipelines, and running the initialization script on the windows server throws "check_win_containers_enabled : Windows Containers must be enabled" error
This seems to require some windows features to be enabled manually, here are the commands to run on powershell:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Enable-WindowsOptionalFeature -Online -FeatureName Containers -All
The shell will also ask to restart after running these commands, here is where i found the answer https://www.jfrog.com/confluence/display/JFROG/Troubleshooting

Disabling Internet Explorer thru Powershell

Trying to disable Internet Explorer but is receiving a prompt whether to complete the operation now? [Y/N]?
Tried this command:
Disable-WindowsOptionalFeature -FeatureName Internet-Explorer-Optional-amd64 -Online -Confirm:$false
Tried this command:
Disable-WindowsOptionalFeature -FeatureName Internet-Explorer-Optional-amd64 -Online -Confirm:$false
But received an error message:
I agree with the suggestion given by Santiago.
The correct command to disable the Internet Explorer using the Powershell is as below.
Disable-WindowsOptionalFeature -online -FeatureName internet-explorer-optional-amd64
When you run the command, it will ask you whether you would like to restart the machine or later. You could enter the desired choice.
Note: Make sure you are running the Powershell as Administrator.

Enable Development time IIS support from PowerShell

I like to keep a PowerShell script that installs and configures my development applications (Visual Studio, VSC, Git etc etc) and environment, mainly using chocolatey. This helps if I change machine or we take on a new developer.
Here is part of my existing script. It installs Visual Studio 2019 and required workloads then enables the local IIS Windows Features for local debugging:
choco install -y visualstudio2019professional
choco install -y visualstudio2019-workload-netweb
choco install -y visualstudio2019-workload-data
choco install -y visualstudio2019-workload-manageddesktop
choco install -y netfx-4.5.2-devpack
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-WindowsAuthentication
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-ASP
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-ASPNET45
Enable-WindowsOptionalFeature -Online -All -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -All -FeatureName WCF-HTTP-Activation
Enable-WindowsOptionalFeature -Online -All -FeatureName WCF-HTTP-Activation45
I have recently come across the requirement to enable "Development time IIS support" in the Visual Studio Installer for .NET Core applications as per https://devblogs.microsoft.com/dotnet/development-time-iis-support-for-asp-net-core-applications/#development-time-iis-support. Is there a way I can do this from PowerShell?
I've figured it out...
choco install -y visualstudio2019-workload-netweb --package-parameters "--add Microsoft.VisualStudio.ComponentGroup.IISDevelopment"
References:
https://learn.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2019
https://learn.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-professional?view=vs-2019&preserve-view=true#aspnet-and-web-development

How to enable Windows features "MSMQ Server" and "MSMQ Server Core" using PowerShell?

I am trying to enable Windows features "MSMQ Server" and "MSMQ Server Core" using PowerShell with the below command:
Enable-WindowsOptionalFeature -Online -FeatureName 'MSMQ-Server' -All -NoRestart
But the above command enables only the "MSMQ Server" and not "MSMQ Server Core". I want a PowerShell command which enables both "MSMQ Server" and "MSMQ Server Core" feature. Any help on this will be highly appreciated.
Thanks,
Mani Athreya S
If you want to enable all MSMQ features, you can run this command. For the record, I do not see a MSMS-Server-Core feature available in my up-to-date Server 2019 VM.
Get-WindowsOptionalFeature -FeatureName MSMQ* -Online |
Enable-WindowsOptionalFeature -Online -NoRestart -Verbose

Install hyperv cmdlet on workstation

I have a script that starts new HyperV VM's on a remote server using powershell
New-VM
Get-VM
I want to run this script on my desktop, however I get the following error.
the term 'new-vm' is not recognized as the name of a cmdlet
I can't figure out how to install the new-vm cmdlet on my workstation
Get-WindowsFeature
the target of the specified cmdlet cannot be a windows client-based operating system
Install-windowsFeature hyperv-
the target of the specified cmdlet cannot be a windows client-based operating system
I am very new to powershell, and don't do much with windows.
How can I install the cmdlet New-VM on a Windows 8 machine?
Update
Also tried the following.
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V-Tools
Enable-WindowsOptionalFeature -Online -FeatureName Hyper-V-PowerShell
I see hyperv tools in the following command
Get-WindowsOptionalFeature -Online | sort state
Microsoft-Hyper-V
Microsoft-Hyper-V-Tools-All
Microsoft-Hyper-V-Management-Powershell
Update 2
I almost got it installed, but it gives this error:
PS C:\Windows\system32> Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management-Powershell
Enable-WindowsOptionalFeature : One or several parent features are disabled so current feature can not be enabled.
At line:1 char:1
+ Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management- ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-WindowsOptionalFeature], COMException
+ FullyQualifiedErrorId : Microsoft.Dism.Commands.EnableWindowsOptionalFeatureCommand
PS C:\Windows\system32>
Got it installed. The powershell cmdlet has parents that can be installed by adding -all.
Enable-WindowsOptionalFeature -online -FeatureName Microsoft-Hyper-V-Management-Powershell -all
You will need to reboot before the cmdlet is available.