<p>Trying to get the <a href="https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/#optional-kubectl-configurations-and-plugins" rel="nofollow noreferrer">auto-complete</a> feature of <code>kubectl</code> working with an alias of <code>k</code>, using <code>Windows PowerShell</code> and <code>PowerShell Core</code> on Windows Server 2022, but can't get it to work</p>
<p>tested with</p>
<pre><code>echo 'Set-Alias -Name k -Value kubectl' &gt;&gt; $PROFILE
kubectl completion powershell &gt;&gt; $PROFILE
</code></pre>
<p>or even simply this to try to get it working in the same session, without worrying about saving it to the PowerShell profile</p>
<pre><code>Set-Alias -Name k -Value kubectl
kubectl completion powershell | Out-String | Invoke-Expression
</code></pre>
<p>Results so far:</p>
<p><strong>Powershell 5.1</strong><br />
Tab completion with <code>kubectl</code>: <strong>OK</strong><br />
Tab completion with <code>k</code>: <strong>Fails</strong></p>
<p><strong>Powershell Core 7.3</strong><br />
Tab completion with <code>kubectl</code>: <strong>Fails</strong><br />
Tab completion with <code>k</code>: <strong>Fails</strong></p>
<p>The results above are tested with both <code>Windows Terminal</code> and <code>cmd</code></p>
<p>Am I missing something obvious? (like I normally do)</p>
<p>Thanks!</p>

display_name
<p>PowerShell completions by alias in cobra supported only from version 1.6.0. kubectl depends on cobra 1.6.0 since v1.26 version. So, you should use kubectl v1.26+ and <a href="https://github.com/spf13/cobra/blob/main/shell_completions.md#powershell-completions" rel="nofollow noreferrer">powershell 5.0+</a></p>
<p>I use it with powershell 7.3, kubectl v1.26.1  in windows 10
but it suggest variants only after typing first letter (it doesn't show select menu without typing any letter)</p>
<pre><code>Set-Alias -Name k -Value kubectl
kubectl completion powershell | Out-String | Invoke-Expression
Register-ArgumentCompleter -CommandName k -ScriptBlock $__kubectlCompleterBlock
</code></pre>
