title: Powershell, JSON and NoteProperty
body: <p>I'm trying to use Zabbix API with powershell to automate some monitoring stuff.
  I'd like to retrieve "items" based on different parameters passed to my function to do something like this : if -itemDescription parameter  is passed, look for this description and/or if parameter -host is passed limit scope to that host etc...
  You can find the method description here : <a href="https://www.zabbix.com/documentation/1.8/api/item/get" rel="nofollow">https://www.zabbix.com/documentation/1.8/api/item/get</a></p>
  
  <p>This is a correct request : </p>
  
  <pre><code>{
  "jsonrpc":"2.0",
  "method":"item.get",
  "params":{
      "output":"shorten",
      "search": {"description": "apache"},
      "limit": 10
  },
  "auth":"6f38cddc44cfbb6c1bd186f9a220b5a0",
  "id":2
  }
  </code></pre>
  
  <p>So, I know how to add several "params", I did it for the host.create method, with something like this : </p>
  
  <pre><code>$proxy = @{"proxyid" = "$proxyID"}
  $templates = @{"templateid" = "$templateID"}
  $groups = @{"groupid" = "$hostGroupID"}
  ...
  Add-Member -PassThru NoteProperty params @    {host=“$hostName”;dns="$hostFQDN";groups=$groups;templates=$templates;proxy_hostid=$proxyID} |
  ...
  </code></pre>
  
  <p>What I don't know however is how to make it conditional. I can't find the right syntax to add a "if" statement in the middle of that line. Something like : </p>
  
  <pre><code>Add-Member -PassThru NoteProperty params @{output="extend";if(itemDescription) {search=$desctiption} } )
  </code></pre>
  
  <p>Thanks a lot guys!</p>
  
  <p>Also, pleaser pardon my English, it's not my 1st language</p>