How I became a terminal customization junky

In the beginning, there was PS C:\>_ I have been a regular PowerShell users for years. Probably about a decade now and I avoided customizing the shell on my workstation for the vast majority of that time. Despite PSRemoting being a thing for almost the entirety of PowerShell’s existence now. For one reason or another, I would usually end up RDPing into a server just to open PowerShell. I did not want to become dependent on modules like PSReadLine or console emulators like ConEmu for fear I would be handicapped when I had to use PowerShell on another system.

Make every day unique with NameIt

Introduction This is half of a tandem blog posting about NameIt. You can catch the other half over at Doug Finke’s Blog. If you’ve landed here first, take a few minutes to go read Doug’s post and get the full background on the history of this project. Doug started NameIt as a simple module to generate random strings based on a template, like ???##, which would give you three random characters and two digits.

Working With The Collection Extension Methods (3 of 3)

Review In Part 2, we took a peek at the Zip method. posh> [System.Linq.Enumerable]::Zip OverloadDefinitions ------------------- static System.Collections.Generic.IEnumerable[TResult] Zip[TFirst, TSecond, TResult](System.Collections.Generic.IEnumerable[TFirst] first, System.Collections.Generic.IEnumerable[TSecond] second, System.Func[TFirst,TSecond,TResult] resultSelector) Play That Func-y Music You may have heard a Func in C# called an anonymous function or a lambda. In the MSDN example, it looks like this. var totalCommission = quarterlySales.Zip(quarterlyRate, (first, second) => first * second).Sum(); In C#, the Zip method is a member of a Collection and in the above example, they are calling the Zip method of quarterlySales collection and passing in the quarterlyRate collection as well as the lambda expression.

Working With The Collection Extension Methods (2 of 3)

Predicates Okay. So, we have this collection. posh> $list Mike Bob Wendy Michele Which has a method called FindAll that takes a Predicate. posh> $list.FindAll OverloadDefinitions ------------------- System.Collections.Generic.List[string] FindAll(System.Predicate[string] match) What is a predicate? WikiPedia simply puts it like this. A predicate is a statement that may be true or false depending on the values of its variables If you’ve written some SQL in your life, a Where clause is a predicate.

Working With The Collection Extension Methods (1 of 3)

Sometimes, when you’re working with some data, you want a little bit more functionality or performance than you get from the run of the mill arrays. This is the first in a series of posts about [System.Collections.Generic.List]. Introductions First things first, Generic Lists are statically typed. PS C:\Temp> $list = New-Object System.Collections.Generic.List[int] PS C:\Temp> $list.add(1) PS C:\Temp> $list.add("two") Cannot convert argument "item", with value: "two", for "Add" to type "System.

The Pester Pipeline

A couple of months ago I published a module to help reduce the amount of code you had to write to build infrastructure validation tests with Pester. Since then, I’ve tried to understand more about how people use Pester. Specifically, how they work with the framework to solve their problems. When you start to look around, the community effort to “Pester all the things” is much larger that I would have guessed.

Continuing To Make PowerShell A Bit More Human

Almost two years ago, I learned about a cool project that does some very clever string manipulation. I started messing around with Humanizer and extending existing Types to add some new properties that show off the functionality of Humanizer. Doug Finke started a project at the same time to do the same thing, but using functions. So, we combined our efforts to create one module, PowerShellHumanizer. I, personally, haven’t done much with it since then.

Testing Powershell Classes

It’s been a busy few months. I recently changed jobs and one of my first projects is building some new custom DSC Resources. I chose to use Class-based resources, because Classes are cool. There were some bumps along the way, one of them being how do you run Unit Tests on such a thing. Part of the reason I went with a Class-based resource was because it would be easy to test.

Reading List

This is a list of books I have read over the years and found interesting and influential in understanding Operations, Business, and most importantly, People. Most of these books are not about Technical Operations or Computer Science, but about understanding complex systems, including how we think. System Thinking Thinking in Systems: A Primer by Donella H. Meadows The Checklist Manifesto: How to Get Things Right by Atul Gawande (my review) Human Thought and Bias On Intelligence by Jeff Hawkins Thinking, Fast and Slow by Daniel Kahneman (my review) Quiet: The Power of Introverts in a World That Can’t Stop Talking by Susan Cain Business Organization The Goal: A Process of Ongoing Improvement by Eliyahu M.

Monitoring With PowerShell and Consul

Getting Started I recently read this article, Consul for Cluster Health Monitoring, and was interested if I could use this to execute PowerShell based health checks. Consul has a Win32 build so it seemed reasonable despite there being no Windows examples in the documentation. Here’s the command I ran to start up a Consul server. Ideally, you’d want a few of these in each physical site and then a Consul agent on each node.

Cross Domain Remoting

I’ve seen a couple questions about cross-domain PowerShell Remoting online this week. I do this often and actually just recently finally started building some tooling around making it easier to work with on a daily basis. http://www.reddit.com/r/PowerShell/comments/37nw55/crossdomain_remoting/ @LogicalDiagram @jsnover @almostjulian @abhik501 Can you point me to solid directions, and what WMF versions are required? — Rob Nelson (@rnelson0) May 28, 2015 I referenced this Scripting Guys article which has some good information on remoting to an untrusted domain.

Blog Refresh

AKA: When a new blog post turns into yak shaving. I’ve seen some questions online about PowerShell Remoting across different domains. It’s not a topic that’s well covered but there is some content available. I wanted to put up a quick post to help people find that content. Well, I’ve replaced my laptop since my last blog post and this one isn’t set up with the Ruby libraries necessary to work with Octopress.

Simple PowerShell File Picker v2

I made a couple of changes to the function to support recursively stepping into directories. I started messing around with this snippet in order to reproduce the functionality of using the Windows OpenFile dialog with a one-liner. Now it’s a bit more than a one-liner, but the GridView UI is actually pretty useful if you don’t know exactly what file you’re looking for.

Simple PowerShell File Picker

Here is a simple function to create a basic graphical file picker.

Inspired by the more robust, but more verbose snippet posted on powershell.com.

Tools: PowerShell Providers & Website Creation

I found two great tools yesterday. Actually, that’s an grossly inaccurate statement. One of the tools I learned about at the PowerShell Summit earlier this year, but was just finally published to GitHub. The second tool isn’t really a tool, but a site indexing a bunch of tools, or frameworks, for generating static websites.

Wasted Time

I have been sitting here staring at my computer for over two hours now. Essentially locked out of my system for a full disk virus scanned enforced by The Man (aka Corporate IT). The scan thrashes my slow laptop harddrive so much that opening even a simple web page requires a Buddhist monk’s level of patience. The job has a runtime limit of two and a half hours. While watching the progress bar—it’s the only thing I can really do—it became clear that the scan would never inspect every file in the time limit. I opened up the log and confirmed there were a lot of scans that were terminated around 2.5 hours. Out of curiosity, I used PowerShell to do some basic analysis of this log.

New Relic is a Bit Sweeter

I’ve been working with New Relic a lot in recent weeks and have deployed their agent several times. Obviously, this required some automation and the best way to automate software installs on Windows is Chocolatey. Unfortunately, New Relic didn’t publish their agents to Chocolatey and the existing packages were out of date.

I brought up the request on the user forum and New Relic expressed interested, but also said, “feel free to give it a try yourself.” So, I did. Here is the .Net agent.

Messing with Photos in PowerShell

In continuing with the habit of building wrappers around .Net libraries mentioned on Scott Hanselman’s blog, I have written a module around James M South’s ImageProcessor.

Here’s an example.

Get-PIPImage -Path C:\Pictures\DSC06199.JPG | 
    Set-PIPImageSize -Width 500 -Height 500 -MaintainAspect | 
    Add-PIPFilter -Filter lomograph | 
    Add-PIPRoundedCorners | 
    Set-PIPImageFormat -Format Png | 
    Save-PIPImage -Path c:\temp\whisky.png

And here is the result.

Whisky

Humanize follow-up

Humanizer helps you generate some nice output, but it’s kind of a pain to use in PowerShell. You can use Update-TypeData to make the syntax easier to work with. Then, your code starts to look more like the examples on the project’s site.

Here’s a simple example.

Add-Type -Path C:\Humanizer\Humanizer.dll

Update-TypeData -TypeName System.Int32 `
    -MemberType ScriptProperty `
    -MemberName ToWords `
    -value {[Humanizer.NumberToWordsExtension]::ToWords($this)}

PS C:\temp> $int = 1234
PS C:\temp> $int.ToWords
one thousand two hundred and thirty-four

Humanize your scripts

This is a quick example of some of the stuff you can do with Humanizer to make your script’s output a bit more user friendly.

Strings from numbers.

PS C:\temp> [Humanizer.NumberToWordsExtension]::ToWords(2)
two

PS C:\temp> [Humanizer.NumberToWordsExtension]::ToWords(253)
two hundred and fifty-three

PS C:\temp> [Humanizer.ToQuantityExtensions]::ToQuantity("box", 4)
4 boxes

Book Review: Thinking, Fast and Slow

I finished this book a few weeks ago and have struggled with how to write a review. Thinking, Fast and Slow by Daniel Kahneman is the most epic self-help book I have ever read. It’s also different in the fact that there is no “do this or that to live a better life” type advise, but simply over 400 pages of examples of hour your brain can fail you in so many situations. That lead probably doesn’t inspire you to pick up this thick tome and commit to absorbing the knowledge within, but this is seriously an extremely important piece of work. If you are a knowledge worker and consider solving problems a primary job function, there is no excuse to ignore this book.

Test All The Things

This is a follow-up to my last post on using PSate for test automation. I demonstrated running Invoke-WebRequest and validating the StatusCode as a simple test for if a site is available. Now let’s take it to the next level and run an artificial transaction. Again, PSate is a handy test runner to manage this and the open-source project, WatiN (pronounced as What-in) is a great tool for automating a real browser.

Test it with Psate

Recently I have been putting effort into learning the art and science of unit testing using Pester and PSate. I was going to write up something on my experiences, but Jakub JareŇ° beat me to it with this”) good article on PowerShell Magazine. If you are new to the idea of unit testing, go read that article and then come back here.

So, what is the point of this article? I was working on an unusual maintenance recently and it was around 4 in the morning and it occurred to me that it would be nice if I had a big dashboard that showed everything was “green”. It can take 15 minutes or more for monitoring to spool up and do all it’s checks and what happens if you forget to re-enable monitoring after the maintenance. Your mind is completely unreliable after a 20 hour day.

One Year

American Visitors I happened to look through all of the previous posts today and found that 2/25/2013 was my first. So, that makes a year and by no conscious effort, 52 posts—one a week on average. The site receives about 500 visits a month from over 40 countries. The most popular post, by far, has been get-storedcredentials-module.

Book Review: The Checklist Manifesto

I thought I would try something new for this post, a book review.

I recently read The Checklist Manifesto: How to Get Things Right and it was one of the best non-fiction books I have ever read. That’s the short of it. Go read the book.

If you are still not convinced, here is a bit more about the book and why I feel it’s a top read for anyone who thinks this blog is even slightly interesting. This is a paragraph from the Introduction.

Angular Posh

I just recently found out about a fun project, PoSH Server that has actually been around quite a while. Executing PowerShell from a web page is a powerful idea for a Windows Administrator. Simply access a URL and get back some HTML formatted data—easy to run and consume the results. Just like everything involving PowerShell, there are a number of way to tackle this and I’ve tried quite a few including: PowerShellASP (now PowerShellServer) by /n Software; and Edge for NodeJS. The beauty of PoSH Server is that it’s written entirely in PowerShell which makes it easy to run and tweak. You don’t even need IIS installed. If you have PowerShell installed, install the module and run Start-PoshServer. That is all. Well, that’s enough to get you started. Where you go from there is the challenging and fun part.

Command line tools

The good folks over a Royal Pingdom posted an article today entitled “Powerful command line tools for network administrators.” Of course, by network administrator, they mean Linux admin. Here’s my version for you Windows admins. I guess you could call it “PowerShell command line tools for network administrators.”

Tools: NSSM

Get-StoredCredentials Module

Password Vault'

If you’re doing security right, the credential you use to log into your workstation is not the same used to managed the Production environment. Because of that practice, I have to run Get-Credential almost every time I open up a new Powershell session and type in details manually. There are plenty of options for storing credentials securely and one has been standard in Windows for over a decade—Windows Credential Manager. Why has no one built a script for getting and setting credentials from this store? Well, it’s exposed through a Win32 API. For all my searching I could not find a .Net class for working with it or even an open source .Net wrapper. There’s just this example code. Fortunately, a few people have pieced together the interesting bits to get credentials out of the Credential Manager. I cleaned up the code a bit and made it a Script Module so it will auto-load when I type the alias gsc.

Powershell Desired State Configuration

Lights Cross Processed by Tarnished_Plastic, on Flickr

Yesterday, Microsoft revealed a new feature of Powershell v4 that is included in Server 2012 R2—Powershell Desired State Configuration. At first glance this looks to compete directly with Chef and Puppet, but during the presentation, OpsCode actually stepped in to present how they’ve already adopted the new technology into Chef. If you already use Chef and are familiar with the Ruby based DSL, you can continue to use it. System Center 2012 R2 is also built on top of this framework. It is the new way of thinking for Windows system configuration automation.

Here is an example configuration script. It only scratches the surface of the capabilities demoed by Kenneth Hansen and Jeffrey Snover at TechEd.

Windows Audio Device Cmdlet

Basic command-line audio device control from Powershell including Nuget Package Manager Console. On GitHub Features: Set Volume and toggle Mute on the Default Playback Device. Get a list of devices and set the Default Audio Device. Install. Download New-Item “$profile\Modules\AudioDeviceCmdlets” -Type directory -Force Copy CoreAudioApi.dll, AudioDeviceCmdlets.dll and AudioDeviceCmdlets.dll-Help.xml Import the binary module. This can go into your profile. Import-Module AudioDeviceCmdlets You may need to set the execution policy.

Software Deployments with psake on Windows

I’m working on the finishing touches of a Deployment Automation script useing psake (pronounced like sake—the Japanese rice wine) as the framework for creating discreet jobs and enforcing dependencies.

This Site: Follow-Up

Following up to the original post.

I’ve been running this site for over a month now and have a full AWS billing cycle report I can share. Rate: $0.095 per GB - first 1 TB / month of storage used Used: 0.179 GB-Mo Cost: $0.02

Tools: Pipeworks

PowerShell Pipeworks is a pretty interesting module for PowerShell. Most modules for Posh are focused on doing some discrete task(s). The design principle of Cmdlets is to make single function executables just like Unix shell commands.

I think Pipeworks is the first 3rd party framework I’ve seen developed on Powershell. It’s scripting glue you can use to build automation with Service Oriented Architecture principles. With PowerShell v3 and the whole Windows Management Framework it was packaged in, there is a new Powershell feature called Workflows. Workflows was designed and released also to solve the problem of orchestrating more complex sequences of logic.

Nginx As a Forward Proxy

Everyone wants to do SaaS these days and that includes Infrastructure Monitoring software. That’s a problem when half of your servers do not have internet connectivity and you’d like it to stay that way.

What this site runs on

I’ve wanted to share some of my my experiences working in a Microsoft based SaaS environment and thought about blogging before, but I’m not really a writer. I finally started this site as an experiment to try technologies that I don’t normally get to try in my day to day professional experience. The site has been up for a few days, no visitors, but maybe someone will read this someday.

.Net

Angularjs

Automated Ops

Automation

Blog

Blogs

Books

Butnotreally

Checklists

Classes

Collections

Consul

Decision Making

Deployment

Devops

Foss

Http

It

Itsajoke

Monitoring

News

Nginx

Opinion

Pester

Powershell

Project

Projects

Projects

Prompt

Psate

Qopy

Random

Reading_lists

Remoting

Saas

Security

Soa

Tags

Teched

Terminal

Testing

Tip

Tips

Tools

V5

Watin

Windows