{"id":2466,"date":"2018-04-25T15:47:47","date_gmt":"2018-04-25T13:47:47","guid":{"rendered":"http:\/\/www.mariotti.de\/?p=2466"},"modified":"2018-04-25T15:47:47","modified_gmt":"2018-04-25T13:47:47","slug":"powershell-args-string-als-hashtabelle","status":"publish","type":"post","link":"https:\/\/dev.mariotti.de\/?p=2466","title":{"rendered":"PowerShell $args String als Hashtabelle"},"content":{"rendered":"<p>Vor kurzem stand ich vor der Problematik bei einem PowerShell Skript beliebige unbekannte Kommandozeilenparameter auswerten zu wollte, bei denen es sich um Key=Value Paare handelte, also eigentlich ideal f\u00fcr eine Hashtabelle, jedoch handelt es sich bei der PowerShell Kommandozeilenparameter $Args Variable immer um einen String. Somit war ich auf der Suche wie man diese Key=Value Paare des Strings in einen Hashtabelle gewandelt bekommen. Dies ist einfach m\u00f6glich mittels dem ConvertFrom-StringData Cmdlet, hier das passende Beispiel:<\/p>\n<pre><\/pre>\n<pre><code class=\"language-powershell\"># Beispiel $args String der mittels Semikolon getrennt ist und Key=Values paare beinhaltet\n$args = \"LicenseKey=12345-67890-ABCDEF;AddLocal=All;User=Andreas\"\n\n# Konvertierung zur Hashtabelle\n$hash = ConvertFrom-StringData -StringData $args.replace(';',\"`n\")\n\n# Abfrage des Hashtabelle Inhaltes (als proof)\n$hash.GetEnumerator() | foreach{ write-host \"$($_.name)=$($_.value)\" }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Im heutigen Artikel zeige ich wie man PowerShell Kommandozeilenparameter ($args Variable) im Key=Value Format in eine Hashtabelle wandeln kann<\/p>\n","protected":false},"author":2,"featured_media":2425,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-2466","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/posts\/2466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2466"}],"version-history":[{"count":0,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/posts\/2466\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=\/wp\/v2\/media\/2425"}],"wp:attachment":[{"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.mariotti.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}