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' | ` Get-UIATreeItem -Name HKEY_LOCAL_MACHINE | ` Invoke-UIATreeItemExpand | ` Get-UIATreeItem -Name SOFTWARE | ` Invoke-UIATreeItemExpand | ` Get-UIATreeItem -Name Microsoft | ` Invoke-UIATreeItemExpand | ` Get-UIATreeItem -Name Windows | ` Invoke-UIATreeItemExpand | ` Get-UIATreeItem -Name CurrentVersion | ` Set-UIAFocus;
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" | ` ConvertFrom-Csv;
Homework: try to export datagrid data from another key in the Registry editor or from the Services snap-in.