Wednesday, April 16, 2014

PowerShell 007 - Building the pipe

A Step Back

OK, so I’m a big fan of get-help. I use it just about every time I sit at the PowerShell_ISE. It is partly because I’m old and can’t remember everything, partly because there is simply too much to know, and, as Jeffrey Snover says “I am a flawed human being”. You should check out the Virtual Academy PowerShell Jumpstart session with Jeffrey Snover and Jason Helmick. These two are great Edutainers. So, even if I forget to mention the help system use it and the community to learn.

As you may know, or possibly not yet, PowerShell is a system that returns objects back on request. Even though you may only see a small bit of data returned to the screen the object returned may include much more data. For a quick example, if I want to look at the most recent log entry in my application log I can type;

PS\> Get-EventLog –LogName Application –Newest 1

This returns something like this.



Index, Time, EntryType, Source, InstanceID and Message. It provides some very important data and often this is all I may need to look at. But if I want to see the whole object I can try;

PS\> Get-EventLog –LogName Application –Newest 1 |format-list *

The above means get the same data but display the object in a list, as opposed to a table, and show me the entire (*) object. It looks like this.



Lots more data. For different cmdlets there is going to be different data returned to the screen, which is a sub-set of the entire object.

I actually did something else here. I ‘piped’ the object returned from one cmdlet to another.

Pipeline

Above the simple example takes the single object output from my Get-EventLog cmdlet into the Format-List cmdlet. Great for organizing your output. What happens if you have a cmdlet that returns a lot of data?

PS\> Get-EventLog –LogName Application |Measure

This counts how many objects to output. Right now I would return a measly 2685 events as individual objects. Small application log but way too much to handle. I want to pipe the output to another cmdlet, Select-Object, to trim down the output a bit.

When I pipe the output to Select-Object I can narrow down based on the properties of the object.

PS\> Get-EventLog –LogName Application | Select-Object –Property EventID, MachineName, –First 20

The above uses Select-Object to only show two properties, EventID and MachineName for the first 20 entries in the log.



You can narrow by any data that you are looking for. What if you want to see Source, or EntryType. Just use those properties in your list and you are good.

I find the pipeline to create an incredibly intuitive, readable system that at first glance can look very complex. It reads like a bit of a work flow.
  1. Get all events in the application log
  2. Select from that list the first 20 events
  3. only prepare the EventID, MachineName, Source and EntryType.
  4. Export the data to a webpage
PS\> Get-EventLog –LogName Application | Select-Object –Property EventID, MachineName, source, EntryType  –First 20 |Convertto-HTML |Out-File .\eventlog.html

Other than some typos…




Wednesday, April 9, 2014

SMH - Windows 8, Windows 8.1, Windows 8.1 Update 1

Not what you are expecting?

My rant du jour is not against Windows and its direction since Windows 7, it is a rant for it. More specifically it is a rant against those so called pundits that have built careers spouting opinion filled nonsense because it collects readers. 

I have been reading about Update 1 for a while as most of us have. I had taken a look at the update on one of my tablets, I waited for my main computer and my laptop until today. I was expecting to not like the update. The reason I didn't think I would like the update is because I felt like Microsoft and the Windows team was bailing. It seemed like they were pandering to whiney, I don't like change people and I personally think that is weak! I love Windows 8 + and I love it on my Surface Pro, my RT, my laptop, my desktop. Touch, no-touch, I don't care. I find the OS elegant, fun and interesting. 

I like the management of it, I like PowerShell, I like the dual experience of modern and classic. I like the cloud integration, I like the device management, I just like it. There were some time where I was frustrated with how I used to do something, but learning how a scenario works on this new OS family is interesting.

When I first installed a Windows 8 machine at home, a long time ago (I was working on the Windows Engineering team at the time so very early previews). I had to keep it to myself. But when it was announced I could install an update that exposed the new UI and start talking about it. It took me some time to get efficient but it was still a very cool experience.

I sat my oldest daughter down, she was probably 10 at the time, and I told her to check out my new computer. I walked away and without any instruction she was finding things, she was painting, creating docs, playing games and enjoying herself. No touch screen, just mouse and keyboard and she loved it and found it very intuitive. 

How can some self-proclaimed experts spew nonsense about the OS without any technical backing? How can someone correlate the drop in PC sales with the OS alone and not take into account that computing is changing fundamentally? I read a piece today on Information Week that was not a bad piece. It was 'Windows 8.1 Update 1: 10 key changes'. OK, great, let's see what was important to them. The article began quoting Paul Thurrott and a couple of others on how they hated Windows 8+. 

Now I have been following Windows since the beginning. I was an MCSE in Windows NT 3.5, I was one of the early MCSEs in Windows 2000 and I have been reading Paul and and others for years. Paul built a reputation on being incredibly helpful to those of us who were learning how these systems works. An incredible resource along with his colleagues. At some point it seems like he realized people cared about his opinion and it has been a decline in value since. The quote in the previously mentioned article was "Windows 8 is a disaster in every sense of the word." OK, taken out of context I'm sure but come on, really. Slackware was a disaster. There were so many great things about Windows 8 even for the haters out there from day 1. The willingness for Microsoft to take a pretty aggressive jump forward in the experience by itself is impressive and very, well, non-Microsoft. 'Disaster'? Really? Vista was a disaster. There was some user research regarding Vista that was interesting. Out of the population surveyed for a given study a very high percentage said that Vista was horrible. Out of those who said Vista was horrible a very low percentage had ever personally seen or used a Vista machine. I'm not going to even bother trying to dig that up because even if I did... haters are going to be haters. It is not even worth the argument. 

I was happy to see that the Update, even though it was pandering a bit IMO, has some pretty great changes. Even though the Information Week article started out negative and had a bit of a negative tone, it walks through these 10 changes that are really interesting and make the usability of the system better. Check out that article here. There are a ton of articles going around. Come up with your own opinions. See what you like and what you don't. Don't listen to the haters, and don't be one. Make up your own mind. If you don't like it fine, but justify it with something a bit deeper than it is a disaster.

SMH

Saturday, April 5, 2014

PowerShell 006 – WMF v5 and OneGet

Windows Management Framework v5 Preview

WMF V5


Jeffrey Snover posted an announcement of the WMF V5 preview on the Windows Server Blog. The post and a download link to get the new bits is here.

There are a few very interesting pieces here and it is another step in the growth of the framework and PowerShell. I’m personally a little unsure of the reach and extension of the framework into realms ‘unmanaged’ or out of the control of Microsoft. When software vendors provide their modules they take responsibility, with the WFM V5 and especially the OneGet functionality the line is a bit blurred. Who is responsible if OneGet isn’t working? MSFT? Chocolatey? other source providers? At the end of the day, OneGet is pretty cool.

OneGet


From the Windows Server Blog “OneGet is a new way to discover and install software packages from around the Internet. It will simplify the acquisition of all kinds of software and make installation and discovery ‘easy peasy’ as they say.

Much of the OneGet capability is very interesting. I have a few areas that cause me some concern. I’m am willing to be convinced so I’ll spend some time checking it out.  After I setup WMF 5 this morning I used the Get-Command cmdlet to find the OneGet cmdlets. After I found the basics I ran;

PS C:\> Find-Package |Export-csv packages.csv

This first informed me that it needed to retrieve NuGet Package Manager. It then gave me a list of all of the packages available via the provider Chocolatey. There are roughly 1750 packages today (4/4/2014). I wanted to learn more so I decided to check to see if my help files were up to date.

PS C:\> update-help

Uh Oh! update-help throws an error when grabbing help on the ‘OneGet’ and ‘NetworkSwitch’ Modules. Honestly not a great place to start but it is preview! So, learning what parameters are required, mandatory, allow for wildcards etc. may have to wait a bit. Or I can just sit at my computer for hours trying different things!

I did look through my .csv file and found Notepad++ and I decided to set that up.

PS C:\> Install-Package -Name notepadplusplus

After a brief warning about the package not being marked as safe and me ignoring the warning, it downloaded any dependencies and installed the package. Pretty cool if you ask me.

NetworkSwitch


Last year at TechEd I ran into Jeffrey between sessions and had a chance to catch up. Jeffrey is an incredibly accessible guy and so enthusiastic. Just a great person to chat with. I have a few great Jeffrey Snover stories from some projects I had the pleasure of working while at Microsoft, but those are for a different post <G>. During that brief discussion Jeffrey shared with me how one of his visions around Desired State Configuration (DSC) was managing switches, well… here we are! Read through the Windows Server Blog announcement on WMF v5 Preview to learn more about this capability.