title: Using response from Azure cli (json) in PowerShell
body: <p>All I want to do is to see if my IP is already whitelisted for the company key vault and if not then add it.</p>
  <p>The response of <code>az keyvault network-rule list</code> isn't a string (if it was then I could just <code>-match</code> but it's something else and I can't figure out any way to use it in PowerShell.</p>
  <p>This is what I'm trying to do:</p>
  <pre><code>[string] $ip = (Invoke-WebRequest -uri &quot;http://icanhazip.com/&quot; -UseBasicParsing).Content
  
  [bool] $loggedIn = ((((az account show) -match &quot;tenantId&quot;).Count) -gt 0)
  
  if( $b -eq $False ) {
      az login
  }
  
  [bool] $alreadyAdded = (((az keyvault network-rule list --name xxx) -match &quot;$ip&quot;.Replace(&quot;.&quot;, &quot;\.&quot;)).Count -gt 0)
  # The command returns JSON which can't be -match ed and is useless after applying ConvertFrom-Json
  
  if( $alreadyAdded -eq $False ) {
      echo &quot;Adding IP $ip.&quot;
      az keyvault network-rule add --name xxx --ip-address &quot;$ip&quot;
      # It would be good to remove old IPs.
  }
  else {
      echo &quot;Adress $ip is already added.&quot;
  }
  </code></pre>
  <p>This seems to be a way to get the list of current IPs, but it seems to be impossible to test in PowerShell whether this list contains <code>$ip</code>. Or is there a way?</p>
  <pre><code>&gt; az keyvault network-rule list --name xxx --query &quot;ipRules&quot; | ConvertFrom-Json 
  
  value             
  -----             
  xxx.133.237.168/32 
  xxx.39.179.102/32  
  xxx.8.15.24/32     
  xxx.40.138.215/32  
  xxx.42.242.94/32   
  xxx.36.228.115/32  
  xxx.101.245.58/32  
  xxx.27.46.155/32   
  xxx.103.237.247/32 
  xxx.28.15.154/32   
  xxx.132.244.148/32 
  xxx.132.247.90/32  
  xxx.249.181.76/32 
  xxx.205.197.115/32
  </code></pre>