A Spooky PowerShell Halloween

I shared some code yesterday on Twitter and Facebook, but you may have missed it and I wanted to have a more permanent record so this is it. In the spirit of the holiday I thought it would spooky to have a little fun with the PowerShell ISE.

A spooky Halloween theme for the ISEA spooky Halloween theme for the ISE (Image Credit: Jeff Hicks)

How did I get this? Well first, I recommend you save your existing settings. Run this command in the PowerShell ISE.

This will save current values for settings you are about to change to a CSV file. Then run these commands to change ISE options.

Scary easy, right? These settings will remain even if you restart the PowerShell ISE. To restore your original settings and sanity you can import the saved CSV:

Or go to Tools – Options – Manage Themes and select the default, or whatever you are using.

Restoring the ISE themeRestoring the ISE theme (Image Credit: Jeff Hicks)

Happy Trick or Treating!

PowerShell Friday Fun: Capture the Command

This week’s Friday Fun actually has a purpose, at least for me. But I always hope you’ll pick up a tip or two that you can use in your own PowerShell work.

Because I write a lot about PowerShell, I am constantly copying pasting between my PowerShell session and usually Microsoft Word. Although the same is true when I am writing help examples for my functions. I can save command output to the clipboard with this trick:

But I never know if the command was successful until I paste and then I need to copy the command again. Over the years I’ve come up with a number of tools to make this process easier but now I think I finally have it.

My new command is called Out-Copy. It is designed to accept any PowerShell command. The function will essentially pass the results back to the pipeline, so it is like Tee-Object in that respect. It also sends a copy of the output to the clipboard. But wait there’s more! The clipboard output will include the prompt and the command you ran.

At a PowerShell prompt I can run something like this:

Using Out-CopyUsing Out-Copy (Image Credit: Jeff Hicks)

And I can then paste into another application

Pasted resultsPasted results (Image Credit: Jeff Hicks)

I also included a parameter to only copy the command to the clipboard. This command runs as expected:

Copying command onlyCopying command only (Image Credit: Jeff Hicks)

With this result:

Command only resultCommand only result (Image Credit: Jeff Hicks)

This version of my function will only copy what is sent to the success pipeline. It will not capture anything from the other streams such as Verbose, Warning or Error. Normally I do screen shots of that anyway. But this might be something I’ll look into later.

Here’s the complete function which includes an alias.

The only other parameter is Width. I have given this a default value of 80 which works best when pasting into a Word or text document. You can adjust this, typically up to the width of your PowerShell host. Anything beyond will be truncated.

I spent a few hours polishing this up, but it will save me time and frustration from here on out and maybe you will need to use it to. Plus it puts a smile on my face when I use it because I feel like I’m performing magic.


What Are You?

Here’s a quick way to tell whether a given machine is real or not: check the Win32_Baseboard class. You can use either Get-WmiObject or Get-CimInstance. Notice the results from a few physical machines.

Now see the result when querying a Hyper-V virtual machine:

I don’t have any VMware available so I don’t know what kind of result that would show. I also haven’t done extensive testing with items like a Microsoft Surface. I threw together this simple function you could use.

Have fun.

Advice, solutions, tips and more for the lonely Windows administrator with too much to do and not enough time.