Scripting Wife Learns to View Data with Out-GridView

ScriptingGuy1

Summary: The Scripting Wife learns how to view and to sort data by using the Out-GridView Windows PowerShell cmdlet.

I just finished with a fun conference call with a colleague in which we were talking about how to best work with the community. Originally scheduled as a 30-minute meeting, the phone call ended up taking an hour and 15 minutes. It is fun to converse with a like-minded individual, and we started to make some useful connections to accomplish things that lead to a stronger community experience.

I just received confirmation that I will be speaking at the SQL Saturday #70 conference in Columbia, South Carolina on March 19, 2011. The SQL Saturday conferences are community generated, and free. They are an awesome way to meet people, and excellent learning opportunities. It is not only SQL either; I have been to many conferences where they had an entire Windows PowerShell track. One can accomplish many cool things with Windows PowerShell and SQL together in a single application. See the SQL articles on the Hey Scripting Guy! Blog for more ideas about Windows PowerShell and SQL.

I am in my office listening to AC/DC and reflecting on previous SQL Saturday presentations when the Scripting Wife walks in.

“What are we listening to,” she queried.

“It’s called music,” I replied in a somewhat snarky manner.

“Not that,” she rejoined.

“I majored in music for two years at the university, I believe I am in a better position to define what constitutes music than you are,” I said defensively.

“Perhaps, but I am certain you did not study AC/DC in music theory.”

“OK. You got me. To what do I owe this visit?” I asked.

“Do you have time to talk to me about the grid thing?”

“Sure. My next meeting is not until 6:00 tonight, so I have time.”

“I am still working through the output section of the 2011 Scripting Games Learning Guide, and I think I should know about the grid thing.”

“The first thing you need to know is that the cmdlet is called Out-GridView. The second thing is that you can pipeline to it like any other cmdlet,” I said. “Why don’t you go ahead and pipeline process information to it?”

The Scripting Wife thought about it for a minute, and then she entered the following command (gps is an alias for the Get-Process cmdlet.)

gps | Out-GridView

The exact keystrokes she entered appear here (<space> is one press of the Space Bar, <tab> is one press of the Tab key, and <enter> is one press of the Enter (or Return) key).

gps<space>|<space>out-g<tab><enter>

The command and its associated output are shown in the following image. As seen in the screen shot, nothing echoes back to the Windows PowerShell command line when the command is entered.

Image of command output

“Wow! That is cool,” exclaimed the Scripting Wife.

The cool to which she referred is not the blank output in the Windows PowerShell console, rather it is the new window that displays the process information in a grid as shown here.

Image of grid

“One of the cool things about the Out-Gridview is the command that creates the grid appears in the title bar of the command. Another cool thing is that pressing the column heads changes the view by sorting the output, based on that property,” I said.

I show the Scripting Wife the title bar that contains the command, and I show her how to sort the output by handle number by pressing the Handles button. The command name and the Handles button are shown here.

Image with callouts

“There are two things that I find particularly useful about sending process information to the Out-GridView cmdlet. The first is that I like to look at the memory working set,” I began.

“OK, you are getting carried away with the geek speak again. What is memory working set,” she asked.

“Sorry. The working set is the amount of memory that a program uses. Different programs will use different amounts of memory. For example, Notepad typically does not use as much memory as Microsoft Word does,” I said.

“OK. So if my computer seems to be running slowly, I might want to see what program is using up all of my memory,” she asked.

“That is right. Also if a network administrator was testing an application prior to deploying it to the users, the admin might want to see how much memory the program typically uses. If it is too much, then a hardware upgrade might be indicated,” I added.

“That makes sense,” she said. “What is the second thing you like to look at?”

“I also like to look at how much CPU time is being used. To do this, I click the CPU(s) button. Often I have to click it twice, once to bring the small numbers to the top, and once again to bring the large numbers into view,” I said.

After clicking the CPU(s) button a couple times, the display in the following image appeared.

Image of display

“Once you arrange your view to display CPU utilization, you get a pretty good idea of which processes are using the most CPU time,” I said.

“Why don’t you pipeline the results from the Get-Service cmdlet to Out-GridView? You can use the gsv alias to save a bit of typing,” I said.

“OK,” she said.

The command she typed is shown here.

gsv | Out-GridView

The exact keystrokes she typed are listed here.

Gsv<space>|<space>Out-G<tab><enter>

The resulting grid view is shown in the following image.

Image of grid

“Now play around with it a bit. Sort the results by putting the Stopped services on top, and then change it to have the Running services on top. It will work exactly the same as the one that displays the process information.”

“OK. I think I have got it. I am outta here,” she said.

“Where are you going,” I asked.

“Noneya,” she said.

“Noneya? Where is that,” I asked.

“None of your business,” she laughed.

I could tell she was joking, because she laughed. Right?

Join us tomorrow. I will continue working with the Scripting Wife to explore the capabilities of the Out-GridView cmdlet.

The Scripting Wife said you can follow her on Twitter if you wish. I invite you to follow me on Twitter or Facebook as well. If you have any questions, send email to me at scripter@microsoft.com or post them on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.

Ed Wilson, Microsoft Scripting Guy