All posts by Jeffery Hicks

More Power is on the way

P50For the past several months, I’ve been debating about what to do for the next iteration of my Hyper-V network.  I rely on it heavily for my writing, course-ware development, and training.  For awhile now I’ve been traveling with a Yoga 2 Pro which runs a few virtual machines, and a Gigabyte Brix unit with 16GB of RAM and an i7 CPU for everything else.  Because of the two units I also tend to travel with a small 4 port switch plus all the necessary power  supplies and cabling. Even though the Yoga 2 is really light, by the time I pack everything up, as they say, “not so much.”

I also have realized that there are a few more virtual machines I’d like to add to my running network which meant I needed to expand my Hyper-V setup. I was torn between building a mini-ITX solution with this motherboard which could have supported up to 128GB of RAM. I thought that if I needed to travel with it, a mini-ITX wouldn’t be that much of a burden.

Or, I could stick with a laptop. I knew that Lenovo was coming out with a new line of ThinkPad workstations.  So I kept waiting. And waiting. The ThinkPad P50 and the ThinkPad P70 promised to be beasts. At least the specs I wanted. For my purposes, what was most tantalizing was the ability to get a Xeon CPU in a laptop that would support up to 64GB of RAM. Yeah, the unit would be a bit bigger than what I had now at 5.6 lbs but if I maxed out the memory (and why wouldn’t you!), I would only have to deal with a single item at conferences and classes. So I did.

I put in an order for a P50 (the P70 is a 17″ version which was bigger than I really needed).  Even though Lenovo, like most vendors, offers plenty of upgrades, I opted to keep this unit as base as possible. I did get the Xeon CPU and upgraded to Windows 10 Pro (even though I eventually plan to run Windows Server 2016 on it). I also opted for a 2 year warranty with accidental damage  to hedge my bets. Not that I’m expecting any issues but I travel and things happen.  I decided to do my own memory and drive upgrades so save a little money. Right now I’ve invested about $2100 including tax.  I think the memory will be about another $400.  I have a spare drive I’m hoping will work in the P50.

My plan is to set it up as a Hyper-V server in my test domain. When I need to go to a conference, I’ll replicate the VMs I need and go.  The schedule is tight, but I’m hoping to bring it with me to Techmentor so if you will be in Las Vegas and want a P50 tour, be sure to find me.  If nothing else, it should be joining me at the PowerShell Summit.

I’ll be posting pictures, impressions and notes on upgrades as they happen. Much more to come.

Friday Fun: Improved PowerShell Napping

So I had some fun with my post last week on taking a nap with PowerShell. I got some great feedback on Twitter and a new comments on the blog. My initial effort was a relatively simple PowerShell script which certainly got the job done. But I there were a number of areas where I could expand and improve the script and they would be terrific teaching aids. So I did.

The function is defined in a script you can find in Github.

Let’s look at some of the changes I made. First off, I turned this into a function complete with comment based help. You’ll need to dot source the script file into your PowerShell session or profile script to make the command available.

I made just about every option a parameter and added a few parameter aliases as well. So even though I made the Minutes parameter positional so that you don’t need to use the parameter name, you could use –Nap or –Time. You’ll notice I also made the wakeup message a parameter.  Feel free to set your own default value. Otherwise, you can set a different message at different times.

I also realized that if you are napping, someone might still drop by your desk. So I included an option to display a progress bar using Write-Progress. This is a cmdlet that doesn’t get the love it should.

I defined an array of messages:

The messages will be used as the Status property for Write-Progress. I like using a hashtable of parameters to splat when using Write-Progress.

If I use the Progress bar, it is displayed using the seconds remaining.

And every 10 seconds I set the status to another randomly selected message. The result is something like this:

image

The last major change I made per a suggestion was to use the text to speech feature to have a Windows voice “say” the wake up message. I added a parameter for you to specify a voice name which in the US will most likely be David or Zira.  If you don’t know the names, you can specify a bogus value like ‘foo’ and the function will display the available names. This works because I added a validation script to the Voice parameter.

This is probably a bit more involved than most validation scripts.  The main takeaway is that if you use a validation script it has to return either True or False, or throw an exception as I’m doing here. But it works.

image

By adding a voice option I decided the function could either display the message using Write-Host or speak it. The chime happens in either event.

What this meant was that I had to differentiate the parameters which I did with parameter sets.  I specified the default in the cmdletbinding attribute.

Then I needed to specify a parameter set name for each parameter.  If you don’t specify parameter set name, then the parameter will belong to all sets.  Or you can do as I did and be explicit. If you do it properly it should be reflected in the help.

image

You can see that there are 2 ways to use this command. I’ll let you grab a copy and try out the new additions.

Certainly this isn’t a production oriented script but I hope it serves up some interesting examples of different scripting techniques and cmdlets.

As always, comments sincerely welcomed.

Enjoy!

Friday Fun: A PowerShell Nap

antique-watch-150x225I’m hoping that I’m not the only one who feels their butt dragging by mid to late afternoon. Let’s say that’s because we’ve been thundering through the day and by 3:00 we’re a bit out of gas. Yeah, I’ll go with that.

I find myself wanting to close my eyes for only a few minutes to recharge and or at least take the tired edge off.  In other words, I just want a quick nap like we had in kindergarten.  But I need to make sure I wake up! Since I always have a PowerShell console, I can use it as a quick and dirty alarm clock.

For starters I can use the Start-Sleep cmdlet to wait for X number of seconds. So if I want say a 10 minute timer I can run:

But if my eyes are closed how will know when time is up? A quick solution is to make my computer beep using the [console] .NET class.

So to run this all at once I can enter a command like this:

The semi-colon is the end of command marker so what I’m really doing here is executing 2 commands. PowerShell will sleep for 600 seconds and when that command completes, then the Beep() method will run.

But of course it is Friday so let’s have a bit more fun with this.

The Beep() method can also take 2 parameters. The first is a tone frequency, and the second is a duration in milliseconds.

With this in mind I put together a PowerShell napping script.

The script takes a parameter for the number of minutes you need to nap. It then writes a message to anyone who might be walking by your desk to keep quiet.  The script then does a countdown of sorts by calculating a timespan between the target end time and the current time. I’m writing the value as a string so that I can strip off the milliseconds.

nap in progress
nap in progress

At the end of the countdown I’ve recreated a well known chime, at least for those of you in the United States and of a certain age. I’ll let you try it out for yourself.

nap complete
nap complete

So get a bit more work done today,  and when you’re ready, take a quick PowerShell Power nap.

Enjoy and sweet dreams.