About | Links | Scripts
Sharing linux/windows scripts and tips

When it's not cool to use PowerShell.

October 10, 2020 — Jesse Harris

PowerShell is an extremely productive language. The pipeline looping combined with regular expressions and custom objects allow you to quickly build a one-liner that make it tempting to use for data processing. But when it comes to larger data sets, your better off looking to something else.


Vim Quickfix and PowerShell revisited

August 21, 2019 — Jesse Harris

Pretty much any language can be made to work well with Vim without having to resort to Plugins. That's the beauty of it. Vim is a tool, PowerShell is a tool. It's worth getting to know your tools intermitly to become an expert.


Vim Quickfix and PowerShell

June 02, 2019 — Jesse Harris

Enno wrote in with a question on how Ale set's Vim's makeprg and errorformat options when working with PowerShell.


Powershell syntax now supported by ALE (Vim) plugin

April 15, 2019 — Jesse Harris

ALE project has approved my PR to show powershell syntax errors by parsing the powershell by powershell itself. If the current buffer has a filetype of Powershell, the buffer is run through the following powershell script to check for syntax errors. Errors are then displayed in Vim by ALE:


Vim and Powershell

March 31, 2019 — Jesse Harris

Back in the days when Powershell was just a young pup there were a few Vim users contributing to Vim via plugins to make writing powershell a nicer experience. Syntax highlighting, auto filetype detection, snippets and other quality of life things.


The correct way to implement -Whatif and -Confirm in a Powershell Cmdlet

January 08, 2019 — Jesse Harris

When I first learned about [CmdLetBinding()] to add automatic support for Write-Verbose I didn't understand why -WhatIf and -Confirm were not passed to Cmdlets used in my functions.


Introducing PwshBlog

January 01, 2019 — Jesse Harris

Over the holidays I've kept myself busy by porting BashBlog to PowerShell. Although work is by no means complete, you can actually use it to edit an existing blogpost


Setting Powershell as default on MacOS

December 18, 2018 — Jesse Harris

When you click on 'Terminal.app' on a stock MacOS system, your connected to the systems pseudo TTY which in turn launches your users default shell.

Terminal.app can be told to launch a process other than your users default shell (eg, powershell), but there are a few cases where if you might want to replace your shell system-wide. (eg, sudo can use powershell then)


ANSI VT100 colors in Powershell Core prompt

October 19, 2018 — Jesse Harris

Sometime ago I was searching the interwebs for inspiration to spruce up my powershell prompt. I came across someone's prompt they shared on stackoverflow or superuser and unfortunatly I could not find the link again to give proper credit.


First look at powershell 6.1.0

September 15, 2018 — Jesse Harris

Powershell 6.1.0 dropped yesterday. Here is my quick look.

New Commands

Get-Command | Measure-Object on each version:

Version 6.0.4 had 316 commands, while 6.1.0 has 323 commands. Comparing a list of commands:

On 6.0.4: gcm | select -exp name > 6.0.4.txt and the same on 6.1.0, then to compare:

    compare-object (gc ./6.0.4.txt) (gc ./6.1.0.txt)

    InputObject             SideIndicator
    -----------             -------------
    ConvertFrom-Markdown    =>
    Get-ExperimentalFeature =>
    Get-MarkdownOption      =>
    Set-MarkdownOption      =>
    Show-Markdown           =>
    Start-ThreadJob         =>
    Test-Connection         =>
    Test-Json               =>
    more                    <=


Manage a hosts file

September 11, 2018 — Jesse Harris

Most people have long forgotten the lowly hosts file, but from time to time there is still a need to use it.

So I wrote some powershell functions to automate it in a simpler way.


Write-Information > Write-Host

September 06, 2018 — Jesse Harris

June Blender writing for Hey, Scripting Guy! Blog:

The dilemma was how to fix the harmful aspects of Write-Host (can't suppress, capture, or redirect), but keep it from polluting the output stream. And of course, the solution must be backward compatible.

This most elegant solution is provided by the information stream and the Write-Information cmdlet. The information stream is a new output stream that works much like the error and warning streams.

The information stream is a feature of powershell versions 5.x that I missed when it came out. Thus I have been avoiding using Write-Host in favour of Write-Verbose since reading about Write-Host Considered Harmful.

If you care about writing reusable automation friendly code, go have a read.

Tags: powershell, streams

Replacing bash scripting with powershell

September 04, 2018 — Jesse Harris

This article on replacing bash scripting with python was being shared around on twitter today.

The problem is if you want to do basically anything else, e.g. write logic, use control structures, handle complex data... You're going to have big problems. When Bash is coordinating external programs, it's fantastic. When it's doing any work whatsoever itself, it disintegrates into a pile of garbage.

To me, this is what is awesome about PowerShell. I feel like it gets the shell part right, and also supports sane logic, data structures and so on. Sticking to the same language for quick system admin tasks and for longer form script writing really helps learn the ins-and-outs of a language.

As for python, I have started writing some of my regular tools for use on linux in python and so far it just doesn't seem as natural as powershell, although that could just be because powershell is like muscle memory for me.

I'd love to give powershell a better chance on linux, but, it is a bit slow to spin up on the raspberry pi and not available everywhere. For instance to use it on Gentoo, I've got it installed as a snap.

If you have any comments or feedback, please email me and let me know if you will allow your feedback to be posted here.

Tags: shells, bash, python, scripting, powershell

Ip addresses on your subnet with xargs

September 01, 2018 — Jesse Harris

xargs strikes again. This time I'm going to use it's parallel feature to ping 255 machines very quickly. xargs has a parem -Px where x is the number of parallel processes to spawn of the subsequent process.


Xargs tips

August 31, 2018 — Jesse Harris

After 12 years being a Windows admin, I've now used powershell more than other languages so I'm pretty fluent in it's syntax. So it makes me happy when I stumble upon bash/linux scripting paradigms which have been brought over to powershell.


Win32 OpenSSH Package

August 14, 2018 — Jesse Harris

Update 20/09/2018

Updated the script to UseBasicParsing so it works on Server core out of the box. Also, if you have to allow the port on Windows Firewall:

New-NetFirewallRule -DisplayName "Allow SSH" -Direction Inbound -LocalPort 22 -Protocol TCP -Action Allow

Update 11/09/2018

I've made a copy of this script which downloads the dependencies (including PSCore. Also of note, on a machine I ran it on, I had to set the allowed .Net TLS modes before it would let me download from github.

[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"