Hi Luc,
can you please suggest what needs to be modified to get following functionality.
what i want to achieve is if there is no response in orange line within 10 seconds it shud move to next snippet .
$vms_tools_upgrade_needed=$vms | Where-Object {$_.Guest.GuestFamily -eq 'windowsGuest' -and $_.ExtensionData.guest.toolsversionstatus -eq 'guesttoolsneedupgrade'}
write-host "there are" $vms_tools_upgrade_needed.count "windows vms pending for tool upgrade in " $cluster.name -ForegroundColor Yellow
$response = Read-Host "Would you like to update vmware tools?"
if ($response -eq "yes")
{
Write-Host "based on your response updating vmware tools which will take into effect in next powercycle " -ForegroundColor Green
#code
if($response -eq "")
{
Start-Sleep -Seconds 10
Write-Host "moving to next snippet" -ForegroundColor Gray
}
With Read-Host there is no timeout possible.
You can create a loop where you wait for a key press with a timeout.
Something like this for example
$timer = [Diagnostics.Stopwatch]::StartNew()
$answer = ''
while($timer.Elapsed.TotalSeconds -lt 10){
if ($host.UI.RawUI.KeyAvailable) {
$answer = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp,IncludeKeyDown")
if ($answer.KeyDown -eq "True"){
break
}
}
Write-Host '.' -NoNewline
sleep 1
}
$timer.Stop()
if($timer.Elapsed.TotalSeconds -lt 10){
Write-Host "`nAnswer : $($answer.character)"
}
else{
Write-Host "`nTimer expired"
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
With Read-Host there is no timeout possible.
You can create a loop where you wait for a key press with a timeout.
Something like this for example
$timer = [Diagnostics.Stopwatch]::StartNew()
$answer = ''
while($timer.Elapsed.TotalSeconds -lt 10){
if ($host.UI.RawUI.KeyAvailable) {
$answer = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyUp,IncludeKeyDown")
if ($answer.KeyDown -eq "True"){
break
}
}
Write-Host '.' -NoNewline
sleep 1
}
$timer.Stop()
if($timer.Elapsed.TotalSeconds -lt 10){
Write-Host "`nAnswer : $($answer.character)"
}
else{
Write-Host "`nTimer expired"
}
---------------------------------------------------------------------------------------------------------
Was it helpful? Let us know by completing this short survey here.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Note that this will not work in the ISE or VSC, only from the PS prompt
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thnaksiam checking this .