<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PowerShell on MXI</title><link>https://mxii.eu.org/tags/powershell/</link><description>Recent content in PowerShell on MXI</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Mon, 08 Jan 2018 02:15:11 +0300</lastBuildDate><atom:link href="https://mxii.eu.org/tags/powershell/index.xml" rel="self" type="application/rss+xml"/><item><title>PowerShell, square brackets and apostrophes</title><link>https://mxii.eu.org/2018/01/08/powershell-square-brackets-and-apostrophes/</link><pubDate>Mon, 08 Jan 2018 02:15:11 +0300</pubDate><guid>https://mxii.eu.org/2018/01/08/powershell-square-brackets-and-apostrophes/</guid><description>&lt;p>This is a follow-up post to the one about &lt;a href="https://mxii.eu.org/2017/03/19/powershell-explorer-square-brackets-and-unicode-paths/">square brackets and Unicode&lt;/a> in PowerShell.&lt;/p>
&lt;p>I discovered recently that there is another PITA character that interferes with my workaround &amp;mdash; it&amp;rsquo;s a single quote, or apostrophe.&lt;/p>
&lt;p>It&amp;rsquo;s fine to start PowerShell inside a folder with an apostrophe in its name, but we have to escape it when using inside Powershell commands or passing into PowerShell from anywhere else.&lt;/p>
&lt;p>Below are my experiments to find the best way to open PowerShell in any folder&amp;hellip; if ever possible.&lt;/p></description></item><item><title>PowerShell, Explorer, square brackets and Unicode paths</title><link>https://mxii.eu.org/2017/03/19/powershell-explorer-square-brackets-and-unicode-paths/</link><pubDate>Sun, 19 Mar 2017 00:55:11 +0300</pubDate><guid>https://mxii.eu.org/2017/03/19/powershell-explorer-square-brackets-and-unicode-paths/</guid><description>&lt;p>Let&amp;rsquo;s make a folder &lt;code>C:\[test]&lt;/code> and try to open PowerShell there from Explorer (using Ribbon or context menu).&lt;/p>
&lt;p>&lt;img src="https://mxii.eu.org/post/2017-03-19-powershell-square-brackets/test-doesnt-exist.png" alt="set-location: Cannot find path 'C:[test]' because it does not exist. At line:1 char:1" />&lt;/p>
&lt;p>Oops!&lt;/p>
&lt;p>Let&amp;rsquo;s see what we can do with this.&lt;/p></description></item><item><title>Parallel processing in PowerShell</title><link>https://mxii.eu.org/2016/09/16/parallel-processing-in-powershell/</link><pubDate>Fri, 16 Sep 2016 21:05:05 +0300</pubDate><guid>https://mxii.eu.org/2016/09/16/parallel-processing-in-powershell/</guid><description>&lt;p>Running arbitrary number of tasks in parallel with PowerShell, while showing overall progress.&lt;/p>
&lt;p>The main disadvantage of the code I provided in &lt;a href="https://mxii.eu.org/2016/08/17/blog-minification-in-a-fancy-way-with-powershell/">previous post&lt;/a> is that it is performed sequentially. We can speed it up by means of parallel processing, since main limiting factor is not an I/O but minifying algorithms performance.&lt;/p>
&lt;p>There are a lot of ways to use parallelism in PowerShell and it wasn&amp;rsquo;t clear for me which one suits well for my task. I.e. to convert my script, which is processing a lot of small files on a local machine.&lt;/p>
&lt;p>It also should:&lt;/p>
&lt;ul>
&lt;li>provide updates in real time;&lt;/li>
&lt;li>keep output table formatting as close to original as possible.&lt;/li>
&lt;/ul></description></item><item><title>Ellipsis function for PowerShell</title><link>https://mxii.eu.org/2016/09/03/ellipsis-function-for-powershell/</link><pubDate>Sat, 03 Sep 2016 00:07:11 +0300</pubDate><guid>https://mxii.eu.org/2016/09/03/ellipsis-function-for-powershell/</guid><description>&lt;p>&lt;em>One more unintended thing arose from another post.&lt;/em>&lt;/p>
&lt;p>I was looking for a way to fit a lot of lengthy paths into console screen by removing less important parts. &amp;ldquo;&lt;a href="https://en.wikipedia.org/wiki/Ellipsis">Ellipsis&lt;/a>&amp;rdquo; is a standard name for such a thing. You&amp;rsquo;re dealing with it every time you&amp;rsquo;re looking at &amp;ldquo;&amp;hellip;&amp;rdquo; in place of something too long to fit into borders.&lt;/p>
&lt;p>Here is my implementation for PowerShell.&lt;/p></description></item><item><title>Blog minification in a fancy way with PowerShell</title><link>https://mxii.eu.org/2016/08/17/blog-minification-in-a-fancy-way-with-powershell/</link><pubDate>Wed, 17 Aug 2016 00:31:11 +0300</pubDate><guid>https://mxii.eu.org/2016/08/17/blog-minification-in-a-fancy-way-with-powershell/</guid><description>&lt;p>There is no built-in support for minification in Hugo engine, which isn&amp;rsquo;t a bad thing on its own. But I had to figure out a way to minify my files while keeping building and maintenance extremely simple.&lt;/p>
&lt;p>At first point I added &lt;a href="https://github.com/tdewolff/minify/tree/master/cmd/minify">minify&lt;/a> for text files. It&amp;rsquo;s a single binary (written in Go), and with a single call it can run recursively over Hugo&amp;rsquo;s public folder, minifying output files in-place, just as I needed.&lt;/p>
&lt;p>But minifying images is a more tricky task. I decided to use &lt;a href="http://jpegclub.org/jpegtran/">jpegtran&lt;/a> and &lt;a href="http://optipng.sourceforge.net/">optipng&lt;/a>, but they can&amp;rsquo;t be run recursively. Some scripting is required to use them. While the task of finding all the images in a folder and applying minifiers on them is trivial and can be solved with PowerShell one-liner, it was not satisfying enough, so I end up with the thing described below in this post.&lt;/p>
&lt;p>Additional motivation is to have a tool that can be adopted easily to any other processing task and will give me a fancy progress report.&lt;/p></description></item><item><title>Quick note about objects in PowerShell</title><link>https://mxii.eu.org/2016/08/12/quick-note-about-objects-in-powershell/</link><pubDate>Fri, 12 Aug 2016 03:14:15 +0300</pubDate><guid>https://mxii.eu.org/2016/08/12/quick-note-about-objects-in-powershell/</guid><description>&lt;p>&lt;em>I decided to move this note out from another post.&lt;/em>&lt;/p>
&lt;p>It&amp;rsquo;s a kind of summary on a question &amp;ldquo;Why &lt;code>[PSCustomObject]@{}&lt;/code> syntax is the preferred way to create objects in PS&amp;rdquo;. After looking into StackOverflow (&lt;a href="http://stackoverflow.com/questions/14012773/difference-between-psobject-hashtable-and-pscustomobject">one&lt;/a>, &lt;a href="http://stackoverflow.com/questions/35894272/powershell-type-accelerators-psobject-vs-pscustomobject">two&lt;/a>) and some other resources (&lt;a href="https://learn-powershell.net/2014/01/11/custom-powershell-objects-and-performance-revisited/">three&lt;/a>), I decided to test and write it down for myself.&lt;/p>
&lt;p>Nothing really new here. I only hope it will work as a good summary.&lt;/p>
&lt;p>&lt;strong>Update:&lt;/strong> Select-Object examples. Additional links.&lt;/p></description></item><item><title>Ways to measure execution time in PowerShell</title><link>https://mxii.eu.org/2016/08/05/ways-to-measure-execution-time-in-powershell/</link><pubDate>Fri, 05 Aug 2016 21:28:11 +0300</pubDate><guid>https://mxii.eu.org/2016/08/05/ways-to-measure-execution-time-in-powershell/</guid><description>&lt;p>Ok, back to business. No electronics at least for a few posts though.&lt;/p>
&lt;p>It will be clear later why I became interested in this topic. But it is, on its&amp;rsquo; own, worth for a post, so here it is.&lt;/p>
&lt;h1 id="measure-command">Measure-Command&lt;/h1>
&lt;p>The canonical way to measure how long something runs in PowerShell is to use &lt;a href="http://ss64.com/ps/measure-command.html">Measure-Command&lt;/a> cmdlet.&lt;/p>
&lt;pre>&lt;code>&amp;gt; Measure-Command { &amp;quot;do stuff&amp;quot; }
Days : 0
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 0
Ticks : 7436
TotalDays : 8,60648148148148E-09
TotalHours : 2,06555555555556E-07
TotalMinutes : 1,23933333333333E-05
TotalSeconds : 0,0007436
TotalMilliseconds : 0,7436
&lt;/code>&lt;/pre>
&lt;p>One notable downside of this is that you see no output from a command. Time span is returned instead.&lt;/p>
&lt;p>What else can we do?&lt;/p></description></item></channel></rss>