I am writing a script to carry out maintenance on several virtual machines running on Hyper-V
As part of this, I need to stop the VMs but if there is any kind of problem with stopping them, I want to abort the process
Problem is, Stop-VM prompts for confirmation if it encounters any problems and there doesn't seem to be any way to automate a response (there are no switches to the cmdlet to control what happens in these cases, -confirm:$false doesn't work, -force is the opposite of what I want, and sending STDIN to the cmdlet gives an error as it expects to receive a virtual machine via the pipeline
As an example, if the integration services are unavailable you get prompted to force a shutdown, which I would want to answer No to:
> stop-vm testvm01
Confirm
Hyper-V can't shut down virtual machine "testvm01" because the Shutdown integration service is unavailable. You can turn off the virtual machine by selecting [Y]es, but this is similar to pulling the power on a physical machine. To avoid potential data loss, select
[N]o, then pause or save the virtual machine. Do you want to turn off the virtual machine?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"):
How can I script a response to this prompt?
0 Answers