How to "Press" yes after script

I’m installing hyper v feature to win 10 machines with script “Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All” after it has downloaded and installing, it promts: " do you want to restart computer to complite operation?" “Yes”, “no” (yes is default).

I would like to automate “yes” answear without pressing anything. This needs to be run ~20 computers, so pressing and waiting would take a lot of time.

 

Tried -confirm, -force and few another tricks without success

You should provide the parameter -NoRestart for Enable-WindowsOptionalFeature and trigger the necessary reboot after the installation seperately. For example with Restart-Computer. :wink:

I found this article, see below, which has a solution.

https://mikefrobbins.com/2018/06/21/use-powershell-to-install-windows-features-and-reboot/

$results = Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
($results.RestartNeeded -eq $true) {
Restart-Computer -Force
}