(MS) UIAutomation: exporting from a grid

Task: export data from the data grid to a text file. As an example, use the Registry editor.

Task #2: provide a field for learning the module.

Requirements: just do it. Navigate through the Registry, find the values and export them to a file.

Solution: run the following code to get to the node:

Get-UIAWindow -Name 'Registry Editor' | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name SOFTWARE | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name Microsoft | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name Windows | `
	Invoke-UIATreeItemExpand | `
	Get-UIATreeItem -Name CurrentVersion | `

After the node is active, we’ll export the values:

	Get-UIADataGrid | `
		ConvertFrom-UIADataGrid | `
		Out-File "$($Env:TEMP)\export.txt";

All the values are already in the file.

ConvertFrom- cmdlets provide standard capabilities as do standard Convert cmdlets from Microsoft. For instance, you can pipeline to the Select-String cmdlet if you need check that a particular value(s) is in the grid.

To find out what was exported to the file, run the following:

Get-Content -Path "$($Env:TEMP)\export.txt" | `

Homework: try to export datagrid data from another key in the Registry editor or from the Services snap-in.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: