Category Archives: How To….

PowerShell Get-Command: finding the cmdlet

A recent Slack chat reminded me that PowerShell’s Get-Command cmdlet is a good way of finding what commands to use when you encounter a new problem. However it goes beyond typing “Get-Command” and just getting a huge list back- my laptop just gave me 7659 commands to choose from – as this can be unusable. Here’s some quick tips on focussing your search by using the built in arguments.

1. –module

PowerShell and it’s extensions are comprised of modules. If you want to use the cmdlets for interacting with a VMware environment you install their “PowerCLI” module. Get-Command can return just the cmdlets from a specific module, for example we can list all the cmdlets from the VMware modules

Get-Command –Module VMware.*

Or we can list the commands in the Azure Compute PowerShell module

Get-Command –Module Az.Compute

2. –verb

If you’ve used PowerShell before, you’ll know that cmdlet names are all of the format verb (“a doing word” as I was taught at school), followed by a dash,  followed by a noun. So we have Measure-Object, Remove-Disk, and even Get-Command itself. The “-verb” argument can be used to only show us cmdlets with this verb, for example to only see the “Get” cmdlets we use

Get-Command –Verb Get

3. –noun

So, after the dash we have the noun. A disk, network connection, user account, and so on. So to find out all the cmdlets that work on or with services:

Get-Command –Noun Service

4. Combining the above

Of course we can make this even more powerful by combining these arguments together and with wildcards. Let’s say we want to know all the cmdlets for working with VMware vSphere tags?

Get-Command –Module VMware* –Noun *Tag*

Or if we want to find all the get Azure get commands for working with resources, resource groups, resource locks and so on.

Get-Command -Module Az.* -Verb Get -Noun *resource*

Improving Documentation via the Community.

Have you ever had to deal with incorrect documentation? Or been frustrated by a typo? Or been annoyed that a how-to guide uses an old version of an interface?

Now you can fix it!

Many software providers are now using community-editable documentation online. This isn’t a Wikipedia style free-for-all, but a carefully moderated process ensuring that the resulting document is accurate.  If you come across an error in an online doc, or even a PowerShell help page, check and see if you can submit edits.

Continuous deployment pipelines mean that these edits can make it into live documentation in a matter of hours or days- impressive times if you’ve ever submitted an errata to a printed book, or submitted a bug request to get online documentation fixed.

docs.Microsoft.com

If you visit a Microsoft docs page, you’ll see an Edit link at the top of the screen (see (1) in the screenshot below). Clicking on this takes you to a page on Github with the source of the document. Click there to edit the file and a git fork will be made under your own profile- make your edits and submit a merge request and, once approved, your updates will appear in the original website. You’ll even get a little credit (see (2) in the screenshot below) for your contribution.

image

In this particular example I was following the step-by-step guide and noticed that the wording in the document no longer matched the Azure Portal. I was quickly able to suggest a fix and later that day the page was updated and anyone else following the instructions wouldn’t be misled. Two minutes of my time hopefully saved ten minutes of head-scratching by someone else.

VMware PowerCLI Example Scripts

As the name suggests, the source code for some example PowerCLI scripts has been published by VMware supported by members of the #vCommunity. If you find an error in the scripts you can pop over to Github and correct them- and remember this isn’t just the code of the script, but also it’s accompanying documentation.

image

In this example a typo in the get-help file was spotted and quickly corrected. Whilst the spelling mistake wasn’t a show-stopper this shows how quick and easy it is to contribute to these projects without being a coding guru.

Summary

Many of these projects use Github and learning how to use that version control platform isn’t arduous- especially for small changes like these- and is a useful skill to pickup if you don’t already have it. The important message here is you don’t need to be a developer to contribute to the code.

So, next time you spot a mistake in documentation, see if you can fix it yourself and help the next person who comes along.

Experiences using Microsoft To-Do

2019-04-11_21-39-55-MicrosoftToDOFor over a year now I’ve been using Microsoft’s To-Do application to manage and organise my tasks. This has probably been the longest I’ve stuck with a personal task manager for some time, and I believe the app has just the right amount of features for me, sitting somewhere between Outlook tasks and a more in-depth project management/ planning application. In this post I will discuss how I use the app; you might find To-Do is something you want to check out, or if you’re a current user you might find new ways to use it.

To-Do is not a heavy duty time management application, but it does allow you to manage personal tasks, set due dates or reminders, and have sub-steps if required. For example the “Deploy new Server” task might have “Buy Server”, “Rack Server”, “Configure Network”, and “Install Hypervisor” as steps.

I use the one application for both work and personal tasks, using lists to categorise these but not having a separate application to go to for my non-work tasks. This helps me balance my time focused on the job against my personal time. I believe Work-life balance isn’t just about not working in personal time. When done properly doing some personal activities in work time is balanced against when you have to work in personal time. For example I might answer the odd work email when sat on the couch in the evening, but I won’t feel guilty about instant messaging my family from the office. Microsoft To-Do has a number of features that will help here, not least “My Day”.

My Day is possibly the best feature in To-Do, and can be used similarly to a Work In Progress (WIP) panel on a Kanban board. Tasks from the different categories can all be assigned here, giving me a list of what I need to accomplish next, rather than being overwhelmed by a much longer list. This also allows me to mix those personal and work related tasks – I need to check my VMware licenses today, but I also need to book an appointment at the optician (who won’t be answering their phone when I get home tonight).

When using My Day I set the sort order to put the tasks flagged as important at the top. These are the things I’ve marked that must get done- further down the list are the lower priority things I’d like to get done today, but might not.

2019-04-11_16-06-47-MicrosoftToDo

When starting up To-Do in the morning it offers me the “For Today” listing, so I can pick the tasks I need in my list at the start of today. These may be items passed over from the day before, one’s I’ve had reminders set for today, or emails I’ve flagged and tweets or websites I picked up the evening before for follow up. With To-Do installed on my Android phone I can quickly share from the other apps, for example Twitter or Chrome to automatically create new tasks for my list.

Looking at how my task-lists have evolved, I have general “Tasks” for work related items and “Personal” for non-work ones. I also have a “Learning and Finding Out” list for all those educational links I want to fit in, and a “Blog” list for blog post ideas.

2019-04-11_16-03-06- MicrosoftToDo

In addition to the general work list I have “Delegated/ Parked with Others” for where I have a task which I’ve subsequently passed onto a colleague but want to check back in on progress- things I don’t want to totally disappear from my radar just because someone else is doing the work. I also have a list here for “Project Ideas”; these are those ideas which aren’t quite a task yet, a list of “wouldn’t it be great if we could do x?” or “should we be looking at implementing y?”.

As To-Do is a single-user viewpoint it’s important that it works well with the other work management tools I’m exposed to- project management, collaboration, and service-desk apps can’t just be ignored. My method here is to take those support calls and project actions and add them to my To-Do list, this way I can manage my own time. It’s important to remember that progress updates and documentation need to be recorded in the correct systems, but the use of To-Do as a simple tick list works well for me here.

As someone who has flipped between task management apps and their paper equivalents I’m impressed that I’ve been using To-Do for so long, so if you’re on the lookout for a personal task manager I’d recommend giving it a try. If this app interests you, Microsoft has more details here: https://products.office.com/en-gb/microsoft-to-do-list-app

To Do List

Other task managers are available

PowerShell Maths

A colleague recently popped in a support request after noticing that the Calculator app wasn’t installed on their computer. This prompted an office discussion on how else you can solve sums when sat in front of a computer, and I mentioned you could just use PowerShell.

Open a regular PowerShell window and you can just start typing in basic sums

clip_image001

So addition, subtraction, multiplication, and division work fine- but what else can you do without making it complicated or hard to remember?

PowerShell this comes with the backing of the .NET Maths library, so you can enter [System.Math]:: (or just [Math]:: ) and then tab through possible operations – for example square root (see screenshot), power, trigonometry and so on.

clip_image002

There’s currently 35 methods in this library and you can get a full list of these using the GetMethods property. This example lists them nicely in comma delimited form so you don’t have to scroll this webpage too much 🙂

PS C:\> ([System.Math].GetMethods() |
Select-Object -Unique -Property Name ).Name -join ", "
Abs, Acos, Acosh, Asin, Asinh, Atan, Atan2, Atanh, Cbrt, Ceiling, Cos, Cosh,
Exp, Floor, Log, Log10, Pow, Sin, Sinh, Sqrt, Tan, Tanh, BigMul, DivRem, Clamp,
IEEERemainder, Max, Min, Round, Sign, Truncate, ToString, Equals, GetHashCode,
GetType

So, who needs a graphical Calculator app now?

Quick PowerCLI- Getting VM hardware versions

A quick PowerCLI snippet for examining what VM Hardware versions exist in your virtual environment:

Using the “Group-Object” cmdlet we can run up a quick count of all the VMs on each hardware version

Get-VM | Group-Object Version

Count Name                      Group
----- ----                      -----
42    v13                       {VM1,VM2,VM3...}
257   v8                        {VM4,VM5,VM6...}
70    v11                       {VM7,VM8,VM9...}
2     v4                        {VM10,VM11}
5     v10                       {VM12,VM13,VM14...}
2     v9                        {VM15,VM16}
2     v7                        {VM17,VM18}

This can be refined using “Sort-Object” to put the most common hardware version at the top of the list.

Get-VM  | Group-Object Version | Sort-Object Count -Descending
Count Name                      Group
----- ----                      -----
257   v8                        {VM4,VM5,VM6...}
70    v11                       {VM7,VM8,VM9...}
42    v13                       {VM1,VM2,VM3...}
5     v10                       {VM12,VM13,VM14...}
2     v7                        {VM17,VM18}
2     v9                        {VM15,VM16}
2     v4                        {VM10,VM11}

We may only be concerned with VMs that are Powered On, so “Where-Object” can be used to filter the original list.

Get-VM  | Where-Object {$_.PowerState -eq "PoweredOn"} | Group-Object Version | Sort-Object Count -Descending
Count Name                      Group
----- ----                      -----
66    v8                        {VM4,VM5,VM19...}
51    v11                       {VM7,VM8,VM9...}
33    v13                       {VM1,VM21,VM22...}
5     v10                       {VM12,VM13,VM20...}
2     v9                        {VM15,VM16}
1     v4                        {VM10}

This quick snippet can be useful when establishing the range of hardware versions in an environment, or estimating the amount of work involved in updating VM hardware to a modern standard across an estate.