|
| 1 | +--- |
| 2 | +description: This article aims to guide you through methods to output from PowerShell in formats that are friendly for screen readers, enhancing the accessibility of your scripts. |
| 3 | +ms.custom: experience |
| 4 | +ms.date: 09/12/2024 |
| 5 | +title: Improve the accessibility of DSC output in PowerShell |
| 6 | +--- |
| 7 | + |
| 8 | +# Improve the DSC accessibility of output in PowerShell |
| 9 | + |
| 10 | +Most terminal environments only display raw text. Users that rely on screen readers are faced with |
| 11 | +tedious narration when consuming large amounts of raw text because the raw output doesn't have the |
| 12 | +accessibility metadata to characterize the format of the content. |
| 13 | + |
| 14 | +There are two ways to improve the accessibility of the output in PowerShell: |
| 15 | + |
| 16 | +- Output the data in a way that it can be viewed in another tool that supports screen reading |
| 17 | + technologies. |
| 18 | +- Reduce the amount of output displayed in the terminal by filtering and selecting the data you |
| 19 | + want and output the text in a more readable format. |
| 20 | + |
| 21 | +## Display the data in a tool outside of the terminal |
| 22 | + |
| 23 | +For large amounts of data, rather than output to the host, consider writing output in a format that |
| 24 | +can be viewed in another tool that supports screen reading technologies. You might need to save the |
| 25 | +data to a file in a format that can be opened in another application. |
| 26 | + |
| 27 | +### Out-GridView command on Windows |
| 28 | + |
| 29 | +For small to moderate size output, use the `Out-GridView` command. The output is rendered using |
| 30 | +Windows Presentation Foundation (WPF) in tabular form, much like a spreadsheet. The GridView |
| 31 | +control allows you to sort, filter, and search the data, which reduces the amount of data that |
| 32 | +needs to be read. The GridView control is also accessible to screen readers. The **Narrator** tool |
| 33 | +built into Windows is able to read the GridView details, including column names and row count. |
| 34 | + |
| 35 | +The following example shows how to display a list of DSC resources in a GridView control. |
| 36 | + |
| 37 | +```powershell |
| 38 | +dsc resource list | ConvertFrom-Json | Out-GridView |
| 39 | +``` |
| 40 | + |
| 41 | +The following example shows how to display a list of DSC adapted resources in a GridView control. |
| 42 | + |
| 43 | +```powershell |
| 44 | +dsc resource list -a Microsoft.Windows/WindowsPowerShell | |
| 45 | + ConvertFrom-Json | |
| 46 | + Out-GridView |
| 47 | +``` |
| 48 | + |
| 49 | +The `Out-GridView` command is only available in PowerShell on Windows. |
| 50 | + |
| 51 | +### Character Separated Value (CSV) format |
| 52 | + |
| 53 | +Spreadsheet applications such as **Microsoft Excel** support CSV files. The following example shows |
| 54 | +how to save the output of a command to a CSV file. |
| 55 | + |
| 56 | +```powershell |
| 57 | +dsc resource list | ConvertFrom-Json | Export-Csv -Path .\myFile.csv |
| 58 | +Invoke-Item .\myFile.csv |
| 59 | +``` |
| 60 | + |
| 61 | +The `Invoke-Item` command opens the file in the default application for CSV files. |
| 62 | + |
| 63 | +### HyperText Markup Language (HTML) format |
| 64 | + |
| 65 | +HTML files can be viewed by web browsers such as **Microsoft Edge**. The following example shows |
| 66 | +how to save the output of a command to an HTML file. |
| 67 | + |
| 68 | +```powershell |
| 69 | +dsc resource list | ConvertFrom-Json | ConvertTo-HTML | Out-File .\myFile.html |
| 70 | +Invoke-Item .\myFile.html |
| 71 | +``` |
| 72 | + |
| 73 | +The `Invoke-Item` command opens the file in your default web browser. |
| 74 | + |
| 75 | +## Reduce the amount of output |
| 76 | + |
| 77 | +One way to improve the accessibility of the output is to reduce the amount of output displayed in |
| 78 | +the terminal. PowerShell has several commands that can help you filter and select the data you |
| 79 | +want. |
| 80 | + |
| 81 | +### Select and filter data |
| 82 | + |
| 83 | +Rather than returning a large mount of data, use commands such as `Select-Object`, `Sort-Object`, |
| 84 | +and `Where-Object` to reduce the amount of output. The following example gets the list of Windows |
| 85 | +PowerShell DSC resources that manage processes on the computer. |
| 86 | + |
| 87 | +Each of the following commands improves the output in a different way: |
| 88 | + |
| 89 | +- The `Where-Object` command reduces the number of items returned by filtering the list to only |
| 90 | + show resources that have the word `process` in their type name. |
| 91 | +- The `Select-Object` command selects only the resource type name, kind, and version. |
| 92 | +- The `Format-List` command displays the output in list format, which provides a better narration |
| 93 | + experience for screen readers. |
| 94 | + |
| 95 | +```powershell |
| 96 | +dsc resource list -a Microsoft.Windows/WindowsPowerShell | |
| 97 | + ConvertFrom-Json | |
| 98 | + Where-Object {$_.type -like "*process*" } | |
| 99 | + Select-Object -Property Type, Kind, Version | |
| 100 | + Format-List |
| 101 | +``` |
| 102 | + |
| 103 | +## Additional reading |
| 104 | + |
| 105 | +- [Improve the accessibility of output in PowerShell](https://learn.microsoft.com/powershell/scripting/learn/shell/output-for-screen-reader?view=powershell-7.4) |
| 106 | +- [Out-GridView](xref:Microsoft.PowerShell.Utility.Out-GridView) |
| 107 | +- [Export-Csv](xref:Microsoft.PowerShell.Utility.Export-Csv) |
| 108 | +- [ConvertTo-Html](xref:Microsoft.PowerShell.Utility.ConvertTo-Html) |
| 109 | +- [about_Calculated_Properties](/powershell/module/microsoft.powershell.core/about/about_calculated_properties) |
0 commit comments