Oneliner of the day

Do your fellow VMware Admins sometimes forget to fill in the Notes field for a new vm they create? Or would you like to change those inconsistent notes to something more accurate? Todays oneliner simply copies the Active Directory description field into your Virtual Infrastructure. It’s quite blunt about it. Besides asking if you really want to do so, it shows a lot of errors for servers that are powered off or cannot be found in AD. But it pretty much does the trick.

Get-VM | ForEach { Set-VM -VM $_ -Description (Get-QADComputer ($_ | Get-View).Guest.HostName.Split(“.”)[0]).Description }

If your vm’s always have the same name as defined in the VM Guest OS, you can suffice with:

Get-VM | ForEach { Set-VM -VM $_ -Description (Get-QADComputer $_.Name).Description }

If you want more advanced description synching, check out the full script.



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!