I have been testing a script that helps with various vCenter Server operations. Basically I created a menu with ‘switch’ and execute the code within the menu. In one menu option I list all the hosts in the vCenter server with get-vmhost. I get the proper formatting on the output as expected. On a second pass (staying in the script) the output seems to cut off the first couple of rows. I do not get a title row or the dashed underlines. In my larger script (of which the code below was pulled from) if I progress down the available options then go back to, say , the 1st option it is totally broke, like it never executes the get-vmhost. Restarting the script or ISE fixes the issue (only on first run). What is happening here? Been banging my head against the wall for a week on this and can’t find a reason. Any help in how I can troubleshoot this would be helpful. See below. In selection one I have a sleep -S 3 to be able to see the output in subsequent runs before the cls. I commented out my ‘get-decision’ function to take that out of the mix to see if that caused anything. What the heck is happening here? I’ve been at this problem for a week now.
#temp variables for testing
$user = uuuuuuu
$pwvsan = pwpwpwpw
$vserver = ip of vcenter
#Connect to vCenter
Set-PowerCLIConfiguration -InvalidCertificateAction ignore -confirm:$false > $null
connect-viserver -server $vServer -user $user -password $pwvsan > $null
function get-decision {
$EntRet = Read-Host "Press ENTER to return to the menu"
if ($EntRet.length -eq "") {
show-menu
} else {
get-decision}
}
function show-menu
{
$menu=@"
1 List VM Hosts
2 Power on host VMs
Q Quit
Select a task by number or Q to quit
"@
cls
start-sleep -m 250
write-host
Write-Host "*** VM Utility Menu ***" -ForegroundColor Cyan
write-host
write-host "You have selected vCenter Server: " $vserver -ForegroundColor Green
write-host "You have selected host: " $vhost -ForegroundColor Green
write-host
$sel = Read-Host $menu
Switch ($sel) {
"1" {
write-host
Write-Host "List Host VM's..." -ForegroundColor Green
Write-Host "View vCenter Hosts and statistics on" $Vserver -ForegroundColor Green
$VChostsStat = get-vmhost
$VChostsStat
start-sleep -s 3
#get-decision
show-menu
}
"2" {
write-host
Write-Host "Power on host VMs..." -ForegroundColor Green
#insert your code here
}
"Q" {
Write-Host "Quitting!" -ForegroundColor Green
}
default {
Write-Host "I don't understand what you want to do." -ForegroundColor Yellow
}
}
}
show-menu