To get a better grip on what all exists in the new v3 command space, I wanted to know what I could do with the Get-Command cmdlet in order to get things grouped by Noun. If this is unfamiliar to you, all cmdlets have two parts in their name as a part of the cmdlet design philosophy:
- Verb
- Noun
In the case of Get-Item, the verb is Get and the noun is Item. And, Send-MailMessage has a verb of Send and noun of MailMessage. So, whatever preceeds the dash is the verb and whatever follows is the noun. Fine. Obvious. Duh. I want to do something with this though. And, Visio is coming to mind. So, I need to get my data organized, then, I want a new chart. Thats a little more ambitious.
Ok. Lets see about step 1: organizing the data. To get around the organization I came up with a four step command that:
- Gets the cmdlets
- Selects their full name and noun
- Groups the list based on nouns
- Selects (and expands) the groups once sorted
The command looks like this:
Easy enough. When I run this, just to give a sample, the first 10 lines looks like this:Get-Command-CommandType cmdlet|selectName,@{e={($_.name -split -)[1]};N=Noun} |groupNoun |select-ExpandProperty Group
Cool. Organized, simple, straightforward. Now, for the fun part...i.e., the new puzzle. How can I get these guys into a pretty format in Visio? Or, maybe Word. Ill start with Visio. Using Eds postAdd-BitsFile BitsFileAdd-Computer ComputerCheckpoint-Computer ComputerRemove-Computer ComputerRename-Computer ComputerRestart-Computer ComputerRestore-Computer ComputerStop-Computer ComputerAdd-Content ContentClear-Content ContentGet-Content ContentSet-Content Content
Hey, Scripting Guy! Is It Possible to Automate Microsoft Visio?I was able to come up with something basic, but, it still did not have any kind of decent formatting. It simply put grouped output into rectangles in a Visio document. As I get further into the Visio object model I will try to find a clean, prettier way to put all this together. At the moment, all it does is dump them into a document. Ill actually need to move things around. For now, thats a good bit of time saved. Getting a pretty, well-formed script that really organizes this is probably a round 2 of this effort.
# Instantiate new Visio document$application = New-Object -ComObject Visio.Application# Add document to application$documents = $application.Documents# Open basic diagram template$document = $documents.Add(Basic Diagram.vst)# Select active document page$pages = $application.ActiveDocument.Pages# Select first page$page = $pages.Item(1)# Select basic shapes stencil$stencil = $application.Documents.Add("Basic Shapes.vss")# Get list of cmdlets and group by nounGet-Command -CommandTypecmdlet |Sort Noun|Group noun|ForEach-Object {# Build label$output+= "$($_.Name)`n"ForEach-Object{# Check to see if group has more than 1 cmdletif($_.Group.Name.Count -gt 1){($_.Group.Name -split `n) |ForEach-Object{# Add cmdlet names to label with new line per cmdlet$output+= + $_ + "`n"}}else{# Add cmdlet names to label$output+= + $_.Group.Name}}# Create new square$item = $stencil.Masters.Item("Rectangle")# Drop square on page$shape= $page.Drop($item, 1.0, 10.6)# Set text to current group name$shape.Text = $output