How to walk / filter on a TreeView?

Dec 20, 2013 at 8:31 AM
How to walk / filter on a TreeView, like the left side of File Explorer?
Dec 20, 2013 at 11:19 AM
Edited Dec 20, 2013 at 11:22 AM
To walk through tree nodes you can use 'navigation' cmdlets: Get-UiaControlParent, Get-UiaControlFirstChild, Get-UiaControlLastChild, Get-UiaControlPreviousSibling, Get-UiaControlNextSibling and, of course, any of Get- cmdlets to go down the tree, for example:
Get-UiaWindow -n folder_name | Get-UiaTree | Get-UiaTreeItem Desktop | Get-UiaControlNextSibling | Get-UiaControlNextSibling;
UIAutomation works only with controls that are visible, were visible or would be visible (i.e., out of screen).
When working with tree, it's often a necessity to get a node, expand it (Invoke-UiaTreeItemExpand) and only after that you could access its children.
Get-UiaTreeItem bla-bla-bla | Invoke-UiaTreeItemExpand | Get-UiaTreeItem some_child
or sometimes
Get-UiaTreeItem bla-bla-bla | Invoke-UiaControlClick | Get-UiaTreeItem some_child
What did you mean when mentioned filtering? Which action in Explorer (or another tree)?
Dec 20, 2013 at 2:56 PM
Thank you, the "filtering" I mentioned means pick a node which has a pattern of "MyDisk_XXX".
Is that clear?
Dec 20, 2013 at 3:57 PM
This is sooner search with filtering (I initially thought about a feature of tree view GUI to filter on a condition).
Get- cmdlets support wildcards:
Get-UiaTreeItem -Name "MyDisk_*";
Additional options are:
1) search with additional criteria
Get-UiaTreeItem -SearchCriteria @{name="mydisk_*";automationid="*a*";isoffscreen=$false};
These criteria are given as a standard PowerShell hashtable @{param_name="value";bool_param_name=$true;param_name_2="value_@"}, their names are the list of properties you get by running:
(Get-UiaTreeItem -Name some_node).Current
2) the traditional PowerShell filtering:
Get-UiaTreeItem -some_param some_value | ?{ $_.Current.Name -like "*aaa*" }
If you want to have the -Filter parameter, there's no such now (however, if you find all above is not enough to meet your needs, we can create the -Filter parameter).

Version 0.8.7 also supports regular expressions (I'm not sure about 0.8.7 alpha 1, the soonest will support):
Get-UiaTreeItem -Name "MyDisk|otherdisk" -Regex;
Before the new version is here, you could use PowerShell filtering as shown in the example 2:
Get-UiaTreeItem -some_param some_value | ?{ $_.Current.Name -match "aaa" }
Dec 20, 2013 at 4:13 PM
really good, thanks!

发自我的 iPhone

在 2013-12-20,23:57,"apetrovskiy" <[email removed]> 写道:

From: apetrovskiy

This is sooner search with filtering (I initially thought about a feature of tree view GUI to filter on a condition).
Get- cmdlets support wildcards:
Get-UiaTreeItem -Name "MyDisk_*";
Additional options are:
1) search with additional criteria
Get-UiaTreeItem -SearchCriteria @{name="mydisk_*";automationid="*a*";isoffscreen=$false};
These criteria are given as a standard PowerShell hashtable @{param_name="value";bool_param_name=$true;param_name_2="value_@"}, their names are the list of properties you get by running:
(Get-UiaTreeItem -Name some_node).Current
2) the traditional PowerShell filtering:
Get-UiaTreeItem -some_param some_value | ?{ $_.Current.Name -like "*aaa*" }
If you want to have the -Filter parameter, there's no such now (however, if you find all above is not enough to meet your needs, we can create the -Filter parameter).

Version 0.8.7 also supports regular expressions (I'm not sure about 0.8.7 alpha 1, the soonest will support):
Get-UiaTreeItem -Name "MyDisk|otherdisk" -Regex;
Before the new version is here, you could use PowerShell filtering as shown in the example 2:
Get-UiaTreeItem -some_param some_value | ?{ $_.Current.Name -match "aaa" }