The script wait for the an answer to the question in VC.
If I open a new powershell script command window, I am able to answer VM questions with the following command:
get-VM | Get-VMQuestion | Set-VMQuestion -Option "No" -Confirm:$false
What I would like is to have the script continuing and answering the questions one by one automatically.
function Detach-CD-DS{
param([string] $Datastore)
$VM = Get-VM -Datastore $Datastore | sort Name
Foreach ($_ in $VM)
{
if ($_ | Get-CDDrive | Where {$_.ConnectionState.Connected})
{
write-host "Detaching CD/DVD for VM:"$_.Name
$_ | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false -WarningAction:SilentlyContinue
$_ | Get-VMQuestion | Set-VMQuestion -Option "No" -Confirm:$false
}
else
{
write-host "No CD/DVD attached to VM:"$_.Name
}
}
}
My problem is that the script stops and wait for an answer just before I can set up the answer to the question.
And before to run the command to set the CD/DVD to NoMedia, there is no question asked.
How can I script something like:
If (mycommand return question)
{
set answer to the question
run the command
}
Cheers.