If you are an engineer I would think that you have learned that the state of a system can only be chanted by an event. You need an event. What event is it that tells you that the list contents have changed?
Most CmdLets have no way of telling when the data has changed. A few objects returned by a CmdLet may be able to raise a changed event. Do your objects raise any events? Also, when you extract parts of an object using the "Select-Object" command you recreate the objects as custom objects with no methods, events or connections to a source if there is one.
All of this should tell you that you need to create some event that can rerun the function.
Normally we would use events on a control to intercede when the control is activated. The other main method would be to use a timer to periodically provide an event.
In the end you have to see a form as an event driven system and design your solution around these events. This is the hardest thing for experienced non-windows programmers and inexperienced coders to understand. Once this is learned about forms and once any technician learns enough about computer science and engineering to understand how a computer system works then all of this becomes very obvious and easier to work with.
Here is one place to start to get a handle on Windows forms, how they are designed to work by Microsoft and how the forms classes and controls are structured to make coding simple and easy.
https://docs.microsoft.com/en-us/dotnet ... /winforms/
The following is an example of what you will learn by learning what forms are and how they work. I use the "DropDown" event of the ComboBox to refresh its contends. This would work if the query is fast. It would not be a good solution if the query is slow.
Code: Select all
$datastoredropdownbox_DropDown = {
[System.Collections.ArrayList]$datastoredropdownbox.DataSource = Get-Datastore |
Select-Object Name,FreeSpaceGB,@{n='Items';e={'{0} == {1:N2}GB Free' -f $item.Name, $item.FreeSpaceGB}}
Sort-Object -Property FreeSpaceGB -Descending
$datastoredropdownbox.DisplayMember = 'Item'
}
In forms based design in any system starting with early IBM mainframes with text based forms terminal there have been rules on how to use controls to build humanly usable forms. This technology has been around since the beginning and is the foundation of the controls in Microsoft WinForms. Each control relates to a fundamental understanding of how forms need to be deployed and how they need to behave to accomplish data entry and navigation tasks.
If you attempt to design forms by pure guesswork it will put you in conflict with the underlying technology. The technology is not intuitive for non-computer-trained people. YOU must acquire some basic understanding of the intended use of the forms and controls.
A place to start learning is also from the articles written by Sapien people that describe elements of forms design and control usage.
https://info.sapien.com/index.php/guis/ ... -in-events
https://info.sapien.com/index.php/guis/gui-scripting
Explore the whole info center for hundreds of examples and good guidance for building forms.