Oneliner for the road

Okay, so I’ve just announced I won’t  post anything for the coming month. You must all feel very sad.

Well, before leaving you sobbing over an empty feed reader, here’s one more oneliner. One for the road.

Get-VMHost | Sort Name | Get-View | Select Name, @{N=”MemoryGB”;E={[math]::Round((($_.Summary.Hardware.MemorySize)/1GB),0)}}, @{N=”MemoryUsageGB”;E={[math]::Round((($_.summary.quickstats.overallmemoryusage)*1MB/1GB),2)}}, @{N=”Percentage”;E={[Math]::Round(100*(($_.Summary.QuickStats.OverallMemoryUsage*1MB/1GB)/($_.Summary.Hardware.MemorySize/1GB)),0)}}

What the *bleep* does that do? I’ll explain it to you:

  • It grabs your VMware Servers (Get-VMHost)
  • Sorts them by Name (Sort Name)
  • Gets the advanced properties (Get-View)
  • Selects some properties to show you (Select), being:
    • The server Name (Name)
    • Something called MemoryMB, which is the value of the Summary.Hardware.MemorySize property devided by 1 GB and rounded to zero digits.
    • Something called MemoryUsageGB, which is the value of the Summary.QuickStats.OverallMemoryUsage property (which is already in MBs), converted to GBs and rounded to two digits.
    • Something called Percentage, which is 100 times the MemoryUsage in GBs divided by the Memory in GBs, rounded to zero digits.

Can’t you do something like that with Get-Stat?
Sure, but wouldn’t be near as much fun.



Posting Pause (plus bonus oneliner)

I’m sorry to announce that I won’t be able to post anything until the beginning of October. But I will be back, so please keep me in your RSS feed or check back here in a month. I’ll be back full-force, with more awesome one-liners, helpful scripts and fantastic functions!

Here’s a one-liner to show off to your colleagues. What do you do when somebody asks you for a printed overview of the top-twenty volumes on your virtual servers with the least free disk space?

You fire up your trusty Powershell of course! You type a single line of code, press enter and tell them to check the printer. How cool is that?

Get-VM | Where { $_.PowerState -eq “PoweredOn” } | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, @{N=”MBFree”;E={[math]::Round((($_.FreeSpace)/1MB),2)}} | Sort MBFree | Select -First 20 | Format-Table -AutoSize | Out-Printer

Very cool indeed!

See you next month!


Quick VI Toolkit Oneliners

Today, I have some quick-and-easy VI Toolkit ‘Get-VIEvent’ one-liners for you. Let’s get started right away:

To get all events relating to a certain Virtual Machine, try this:

Get-VM “MyVMName” | Get-VIEvent | Format-Table CreatedTime, FullFormattedMessage -AutoSize

To get all errors from the past 24 hours, enter:

Get-VIEvent -Start (Get-Date).AddHours(-24) -Type Error | Format-Table CreatedTime, FullFormattedMessage -AutoSize

To get all errors related to a cluster, type:

Get-Cluster “MyClusterName” | Get-VIEvent -Type Error | Format-Table CreatedTime, FullFormattedMessage -AutoSize

Finally, to get all events related to DRS:

Get-VIEvent | Where {$_.FulFormattedMessage -match “DRS”} | Format-Table CreatedTime, FullFormattedMessage -AutoSize

As you can see, the possabilities are endless!

Search your Log Files (Helpful Script of the Day)

Today’s Helpful Script of the Day is a handy little script I cooked up that allows you to search the  recent entries of your VMware log files straight from the Powershell Console.

It works like this:

First, it would like to know what string you are looking for. Maybe it’s the name of a virtual machine, maybe the word Error, maybe a specific date and time (note however that each log has it’s own date / time format).

Then it tries to check whether or not you are connected to a server already by looking at the value of the $DefaultVIServer variable. (If you have a definitive way to determine whether or not you’re connected: let me know in the comments.) If you’re not connected, the script will ask which server to connect to. You can connect to Virtual Center Servers or ESX Servers.

Then it checks which log files are available. It will loop through all of them, checking if your search string is found.

It then displays the most recent matches found. You can modify the $maxResults value in the script to adjust it to your needs.

Find-VMLog (Rename to .ps1)

Hope it’s Helpful!


VI Toolkit v1.0 Update 1

The guys at VMware (Carter Shanklin specifically) have really listened to their Community. We were all very excited about the release of the VI Toolkit, but for some reason the frequently used command Get-VM was much slower than it was in the Beta. Carter’s promising improvements with the VI Toolkit v1.0 Update 1.

Thanks Guys!

Getting Started with the VMware Update Manager Powershell Snap-In

When you install VMware Update Manager Update 2 on your Virtual Center Server and then you install the plugin from your VI Client ánd you have the VI Toolkit installed, you have the option to install the Powershell extensions for Update Manager. They are still in beta though, so only use them on your testing environment.

You have to load the extensions in order to be able to use them. This is how:

Add-PSSnapIn VMware.VumAutomation

In order to list all new cmdlets in this snapin, try this:

Get-Command -PSSnapIn VMware.VumAutomation

That should get you on your way of exploring this great addition to the VI Toolkit. Here’s a nice one-liner to keep you busy:

(Get-Compliance (Get-VMHost (Read-Host “ESX Server”))).NotCompliantUpdates


Really Quick Server Info

Today’s Helpful Function of the Day is a great one to store in your profile. (Don’t know how to create or update your own custom profile? Read this.) It’s syntax is a simple as:


It returns server information such as Operating System Version and Service Pack, Active Directory Description and Parent Container (Organizational Unit) and the Model of the computer (e.g. Proliant DL380 G3).
It also supports the use of wildcards in a server name. It will return the same info for all matches.

All of that in just 4 lines of powershell code. Gotta love it!

Get-MyServer (Rename to .ps1)

Powershell Talks Back

Eric Sloof found a simple way to make your Powershell scripts talk back to you. It’s hilarious!

Check it out here.

Keep Your Server Descriptions Synchronized

Today’s “Helpful Function of the Day” is my attempt to help you keep your server descriptions in sync.

You use it by placing it in your profile, or by dot-sourcing the script, or by adding the function to one of your own scripts. The syntax is:

Check-Description [-ServerName] <YourServer> [-SkipIdentical]

If you would like to check or update the description of one server, first connect to Virtual Center (Connect-VIServer), then run: Check-Description SERVERNAME. The script will return the description from the VI Client (if the server is a vm), from Active Directory (if it is found in AD) and from the registry of the server itself (the so-called Browse Comment). It then displays a menu which allows you to select one description as the correct description. It will then update the other descriptions (unless they are unavailable).

In case you would like to check a big list of servers to see if the descriptions are in sync, you use the command as follows:

Get-QADComputer -SearchRoot “OU=Servers,DC=mydomain,DC=com” -SizeLimit 0 | ForEach { Check-Description $_.Name -SkipIdentical }

This command will process all found servers. You can also process a list of servers from a textfile like so:

Get-Content D:\servers.txt | ForEach { Check-Description $_ -SkipIdentical }

The SkipIdentical switch will cause the script to output the servername and description if the descriptions are all in sync. This will speed up using the script, because it will not ask for your input for each and every server, only for those where the descriptions are not identical.

Check-Description (Rename to .ps1)

Questions and remarks are welcome in the comments!


Getting Video Hardware Acceleration Level

This “Helpful Script of the Day” will determine the Video Hardware Acceleration Level for each of your Virtual Machines. Setting the Acceleration to Full will prevent choppy mouse movement when using the console. You can just as easily adjust the script to run against a list of servers of even get the server list from Active Directory. The script works on both physical and virtual Windows servers. Note that a AccLevel of 5 corresponds to No Acceleration and a AccLevel of 0 to Full Acceleration.

Get-VMAccLevel (Rename to .ps1)

Need help? Got a comment? Drop me a line.