{"id":4809,"date":"2017-06-21T22:16:22","date_gmt":"2017-06-21T20:16:22","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=4809"},"modified":"2017-06-22T08:22:24","modified_gmt":"2017-06-22T06:22:24","slug":"powershell-searching-in-arrays","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/powershell-searching-in-arrays\/","title":{"rendered":"Powershell: Searching in arrays"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_4809 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_4809')){$('.twoclick_social_bookmarks_post_4809').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Powershell%3A%20Searching%20in%20arrays\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Athis%20is%20a%20really%20often%20requiered%20task%20in%20powershell.%20Here%20are%20some%20examples.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/powershell-searching-in-arrays\\\/\",\"post_id\":4809,\"post_title_referrer_track\":\"Powershell%3A+Searching+in+arrays\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>this is a really often requiered task in powershell. Here are some examples.<br \/>\n<!--more--><br \/>\nThis is our array<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray=@(\r\n\t&quot;Entry&quot;,\r\n\t&quot;Entry1&quot;,\r\n\t&quot;entry2&quot;,\r\n\t&quot;entry2&quot;,\r\n\t&quot;Entry3&quot;,\r\n\t&quot;Entry4&quot;\r\n)\r\n<\/pre>\n<p>Use the contain operator to search for an whole entry case insensitive. The contain operators simply returns $true or $false<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -contains &quot;entry1&quot;\r\nTrue\r\n<\/pre>\n<p>The same case sensitive<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -ccontains &quot;entry1&quot;\r\nFalse\r\n<\/pre>\n<p>Check if an entry is not present, case insensitive<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -notcontains &quot;Entry10&quot;\r\nTrue\r\n<\/pre>\n<p>and case sensitive<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -cnotcontains &quot;Entry1&quot;\r\nFalse\r\n<\/pre>\n<p>By using the like operator it is also possible to use wildcards for searching. * is a wildcard for non,one or more than one character, ? exactly for one character<br \/>\nThis searches case insensitve for all items which begins with &#8220;entry&#8221; <\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -like &quot;entry*&quot;\r\nEntry\r\nEntry1\r\nentry2\r\nentry2\r\nEntry3\r\nEntry4\r\n<\/pre>\n<p>Same case sensitive<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -clike &quot;entry*&quot;\r\nentry2\r\nentry2\r\n<\/pre>\n<p>And the same negotiated case insensitive<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -notlike &quot;Entry?&quot;\r\nEntry\r\n<\/pre>\n<p>And case sensitive<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\r\n$aMySearchArray -cnotlike &quot;Entry?&quot;\r\nEntry\r\nentry2\r\nentry2\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this is a really often requiered task in powershell. Here are some examples.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[344,9,2],"tags":[957,1049,1048,1053,1050,1047,1045,1046,840,1052,1051,133,794],"class_list":["post-4809","post","type-post","status-publish","format-standard","hentry","category-powershell-scripting","category-scripting","category-windows","tag-array","tag-ccontains","tag-clike","tag-cnotcontains","tag-cnotlike","tag-contains","tag-in","tag-like","tag-match","tag-notcontains","tag-notlike","tag-powershell","tag-search"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/4809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=4809"}],"version-history":[{"count":2,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/4809\/revisions"}],"predecessor-version":[{"id":4811,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/4809\/revisions\/4811"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=4809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=4809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=4809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}