<p>I want to map the host port 5000 to the minikube port. The command already works in the bash but now I need it in PowerShell.</p>

<p>I have already changed the bash command to the point "Code in PowerShell" and now only need to replace the <code>awk</code> command.</p>

<p>Code in Bash:</p>

<pre class="lang-bash prettyprint-override"><code>kubectl port-forward --namespace kube-system $(kubectl get po -n kube-system | grep kube-registry-v0 | awk '{print $1;}') 5000:5000
</code></pre>

<p>Code in PowerShell (<code>awk</code> to be replaced)</p>

<pre class="lang-bsh prettyprint-override"><code>kubectl port-forward --namespace kube-system $(kubectl get po -n kube-system | Select-String -Pattern "kube-registry-v0" | awk '{print $1;}') 5000:5000
</code></pre>

Sibylla Heckmann
<p>Here's a way to do it.  Select-string actually returns on object with multiple properties, and the <code>line</code> property has the string.</p>

<pre><code>kubectl port-forward --namespace kube-system (kubectl get po -n kube-system |
  Select-String kube-registry-v0 | 
  foreach { -split $_.line | select -index 0} ) 5000:5000
</code></pre>

<p>Another way, using <code>where</code> or where-object, and the array index <code>[0]</code> notation:</p>

<pre><code>kubectl port-forward --namespace kube-system (kubectl get po -n kube-system |
  where { $_ -match 'kube-registry-v0' } | 
  foreach { (-split $_)[0] ) 5000:5000
</code></pre>

<p>Similar post about awk and powershell:  <a href="https://stackoverflow.com/questions/30110707/awk-command-to-powershell-equivalent">Awk command to Powershell equivalent</a></p>
