Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 197835

Re: Script stopped with VM question in VC while detaching CD/DVD from VMs

$
0
0

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

(ref: http://www.boche.net/blog/index.php/2012/04/17/using-powercli-to-answer-virtual-machine-message-questions/)

 

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.


Viewing all articles
Browse latest Browse all 197835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>