{"id":4295,"date":"2020-11-18T15:05:12","date_gmt":"2020-11-18T14:05:12","guid":{"rendered":"https:\/\/solidt.eu\/site\/?p=4295"},"modified":"2022-05-23T10:24:01","modified_gmt":"2022-05-23T09:24:01","slug":"powershell-examples","status":"publish","type":"post","link":"https:\/\/solidt.eu\/site\/powershell-examples\/","title":{"rendered":"Powershell examples"},"content":{"rendered":"\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"powershell\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\">$magick = 'C:\\Program Files\\ImageMagick-7.0.10-Q16-HDRI\\magick.exe'\nWrite-Host $magick\n# loop over *.svg files in current directory\n$files = Get-ChildItem -Path \".\" -Filter *.svg\nforeach($file in $files)\n{\n\t$newFile = $file.BaseName + '.png';\n\t# construct the argument array\n\t$args = @('convert', '-background', 'none', '-density', '600', '-resize', '64x64',  $file, $newFile)\n\tWrite-Host $magick $args\n\t# run the command\n\t&amp;$magick $args\n}<\/pre><\/div>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"powershell\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># read first line of file\n$firstLine = Get-Content .\/myfile.txt -First 1<\/pre><\/div>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"powershell\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># loop throug object properties recursively\nfunction Resolve-Properties \n{\n  param([Parameter(ValueFromPipeline)][object]$InputObject)\n\n  process {\n    foreach($prop in $InputObject.psobject.Properties){\n      [pscustomobject]@{\n        Name = $prop.Name\n        Value = $prop.Value\n      }\n      Resolve-Properties $prop.Value\n    }\n  }\n}<\/pre><\/div>\n\n\n\n<div style=\"height: 250px; position:relative; margin-bottom: 50px;\" class=\"wp-block-simple-code-block-ace\"><pre class=\"wp-block-simple-code-block-ace\" style=\"position:absolute;top:0;right:0;bottom:0;left:0\" data-mode=\"powershell\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" data-showlines=\"true\" data-copy=\"false\"># a function\n\nfunction Test-MrCmdletBinding {\n\n    [CmdletBinding()] #&lt;&lt;-- This turns a regular function into an advanced function\n    param (\n        $ComputerName\n    )\n\n    Write-Output $ComputerName\n\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4295","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4295","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/comments?post=4295"}],"version-history":[{"count":5,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4295\/revisions"}],"predecessor-version":[{"id":6205,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/posts\/4295\/revisions\/6205"}],"wp:attachment":[{"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/media?parent=4295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/categories?post=4295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/solidt.eu\/site\/wp-json\/wp\/v2\/tags?post=4295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}