How to copy VMware VM Notes to Computer/AD Computer Account Description

Cover

Computer Name is not always informative enough, for example, the name DC01 will tell you much less than the DC: Site New York - GC, FSMO: Schema, RID, PDC.
Since the computer name NetBIOS/Hostname is limited both in length and in the characters set, to hold the additional information intended a field Description.

Description property

  • It exists either for local computer within Operating System.

Control Panel -> System and Security -> System -> Computer description:

control /name Microsoft.System
sysdm.cpl
  • As well as for Active Directory Computer object:

03.CopyVMNotes_ADDescr

  • This information is important not only for you. It is widely used by monitoring products, such Microsoft SCOM, Lansweeper etc. Would you like to know, coming to work that morning, what ends up disk space not on the server psrv789, but on Main Office Exchange Mailbox 1?

  • If your answer is «yes» or at least «it would not be bad» and your virtual infrastructure is VMware, then the Copy-VMNotes2ComputerDescription.ps1 script from my PowerCLi repo is for you.

Copy-VMNotes2ComputerDescription.ps1

  • Via vSphere Client you will see Notes property as a member of VM Annotations.

04.CopyVMNotes_ThickClient

  • In the Web Client everything is much simpler.

05.CopyVMNotes_WebClient

  • The script uses the intermediate file -HelperCsv parameter to export data to the UNICODE format for the correct displaying of non-English characters.

06.CopyVMNotes_HelperCsv

  • As you already understood, the script takes the VM Notes and replicates them to OS Computer description and/or to AD Computer Description.

  • It controlled by -TargetEnv parameter, which can be either AD, Local or ALL (the default). The parameter is positional and may be omitted.

cd C:\scripts
Get-Cluster PROD | .\Copy-VMNotes2ComputerDescription.ps1 -TargetEnv AD
Get-Cluster PROD | .\Copy-VMNotes2ComputerDescription.ps1 Local
Get-Cluster PROD | .\Copy-VMNotes2ComputerDescription.ps1

07.CopyVMNotes_AD

08.CopyVMNotes_WMI

  • In addition to the Notes itself, the script adds to the Description your custom string (parameter –CustomString) and the Cluster name.

  • The script takes one or more cluster objects, returned by Get-Cluster cmdlet and returns a collection of objects with the following properties.

Property Description
VM VM Name
ComputerName VM Guest Hostname
Cluster Cluster Name
Env Environment AD/Local
VMNotes VM Notes
Error Error message if occured

How to use the script

  • There are three ways. The first and the simplest is to run it as is:

Get-Cluster | .\Copy-VMNotes2ComputerDescription.ps1

But with huge Clusters you will get very long output and will be difficult to follow after the results.

  • Very convenient to use -ErrorOnly parameter to get only failed records, that contain any error:
Get-Cluster | .\Copy-VMNotes2ComputerDescription.ps1 -ErrorOnly | Format-Table VM, ComputerName, Error –AutoSize

09.CopyVMNotes_ErrorOnly

  • The best way in my opinion is to export the results on the fly by Export-Csv while using -Verbose parameter. The -Verbose will give you some statistical info as well.
Get-Cluster | .\Copy-VMNotes2ComputerDescription.ps1 –Verbose | epcsv –notype –Encoding utf8 .\Report.csv

10.CopyVMNotes_Export-Csv

Use -Encoding utf8 if your VM Notes contain non-English characters!

  • Pay special attention to the Error property, it contains an error message if an error occurred. Because these messages can be quite long, especially WMI errors, generated by Get-WmiObject cmdlet, the Error will contain only the first sentence of the error message. This is done using Regex.

11.CopyVMNotes_ErrorTruncate

  • All parameters of the script, except for the -Cluster parameter, are optional and have default values, you can change it on your choice. The following command will get help on script parameters:
Get-Help .\Copy-VMNotes2ComputerDescription.ps1 -Parameter CustomString
Get-Help .\Copy-VMNotes2ComputerDescription.ps1 -Parameter HelperCsv
  • For the full script help, including the examples, run the following command:
Get-Help .\Copy-VMNotes2ComputerDescription.ps1 –Full
Get-Help .\Copy-VMNotes2ComputerDescription.ps1 –Examples

Summary

  • The script does not correct and does not add anything to the existing Description. It completely overwrites the Description value!

  • VM with empty Notes property or VM with non-Windows operating systems, will not be processed by the script.

  • To interact with AD you will need Active Directory Module for Windows PowerShell, which is part of the RSAT (Remote Server Administration Tools).

12.CopyVMNotes_RSAT-ADPSModule

  • Script tries to obtain VM Guest Hostname, if it fails the VM Name used as Hostname, but it must not be the same.

  • The computer from which you run the script must be joined to the same domain as all VM in the cluster. If you have VM in different clusters belong to different AD domains, then run the script for each cluster separately.

  • The user on behalf you run the script must have administrative privileges on the operating system level as well as in Active Directory.

  • VMware virtual infrastructure is a «live» and dynamic environment. Every day the new VM are deployed, VM Notes are added, deleted and edited, you can even rename the cluster. So it makes sense to run this script on a regular basis to keep real objects synced with the virtual.

You may also like:

Set-PowerCLiTitle – Connect-VIServer deep dive
Get-Version – Get any VMware object version
Get-RDM – How to get RDM (Raw Device Mappings) disks
Convert-VmdkThin2EZThick – Convert Thin Provision VMDK disks to Thick

One thought on “How to copy VMware VM Notes to Computer/AD Computer Account Description

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s