> ## Content Index
> Fetch the complete content index at: https://www.techielass.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# PowerShell autocomplete and Windows Package Manager
- URL: https://www.techielass.com/windows-package-manager-command-line-tab-completion/
- Published: 2021-07-13T11:10:00.000Z
- Updated: 2022-01-07T11:36:33.000Z
- Description: Join me as I install auto complete into my PowerShell environment and use it to help me with my Windows Package Manager commands!
- Author: Sarah Lean
- Tags: WinGet, PowerShell, Windows Package Manager, Windows 10, Tip

Autocomplete is something we all like, right? Helps with those moments when we can't quite remember the syntax for a command or where we're learning something new and need some help. I know I've had plenty of those moments. 🤣

I've been really enjoying learning about Windows Package Manager lately and realised the team have pulled together a PowerShell function using **[Register-ArgumentCompleter](https://docs.microsoft.com/powershell/module/microsoft.powershell.core/register-argumentcompleter?view=powershell-7.1&WT.mc%5Fid=modinfra-34190-salean&ref=techielass.com).** 

### Setup Completion

To make use of the auto completion functionality we need to configure our PowerShell environment first. You can either run the command to use it within your current session or you can configure your PowerShell Profile to load it every time you use PowerShell. 

To modify my profile I type in the command

```bash
notepad $PROFILE

```

This will launch a notepad editor opening my PowerShell profile file. In this file I want to add the [PowerShell Command:](https://github.com/microsoft/winget-cli/blob/master/doc/Completion.md?ref=techielass.com#powershell) 

```PowerShell
Register-ArgumentCompleter -Native -CommandName winget -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
        [Console]::InputEncoding = [Console]::OutputEncoding = $OutputEncoding = [System.Text.Utf8Encoding]::new()
        $Local:word = $wordToComplete.Replace('"', '""')
        $Local:ast = $commandAst.ToString().Replace('"', '""')
        winget complete --word="$Local:word" --commandline "$Local:ast" --position $cursorPosition | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}

```

I save the file and close it. 

![Configure PowerShell profile](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2021/07/powershellprofile.PNG)

Configure PowerShell profile

### Using Completion with Windows Package Manager

Now that we have the completion settings configured let's start to use it with Windows Package Manager!

If we start to type the command to trigger Windows Package Manager we can start to use the tab key to complete the command line we need. 

So we start by typing **winget** then we can tab. **Install** is the first command so we will see that, which is the one we want in this example. 

We then want to look for [PowerToys](https://docs.microsoft.com/windows/powertoys/?WT.mc%5Fid=modinfra-34170-salean&ref=techielass.com) so we start typing and find the PowerToys Preview software available to install, by tabbing through the options shown to us. 

Now we want to look at versions, so we can start to type to find that switch within in the Windows Package Manager syntax. The auto completion helps us find the version switch. 

We can now hit tab and it will show us all the versions of PowerToys Preview that is available to install. 

You can see this in action below:

![WinGet in action](https://storage.ghost.io/c/08/96/08960c71-63a2-449b-91b1-8d4628166dd2/content/images/2021/07/autocomplete.gif)

WinGet in action

Or it would look like this in terms of inputs into the keyboard:

| Input                                                                                                                                                                                                                                                               | Result                                                |  |                       |                                      |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------- |  | --------------------- | ------------------------------------ |
| winget ⇥                                                                                                                                                                                                                                                            | winget install                                        |  | winget install power⇥ | winget install "PowerToys (Preview)" |
| winget install "PowerToys (Preview)" --⇥                                                                                                                                                                                                                            | winget install "PowerToys (Preview)" --version        |  |                       |                                      |
| winget install "PowerToys (Preview)" --version⇥                                                                                                                                                                                                                     | winget install "PowerToys (Preview)" --version 0.41.4 |  |                       |                                      |
| Give it a go and let me know how you get on with it! 👌Learn more!If you want to learn more about Windows Package Manager and see a complete overview of it's features, be sure to check out the Microsoft Learn module - Explore the Windows Package Manager Tool. |                                                       |  |                       |                                      |