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
- It exists either for local computer within Operating System.
Control Panel ->
System and Security ->
control /name Microsoft.System sysdm.cpl
- As well as for Active Directory Computer object:
- 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?
- Via vSphere Client you will see
Notesproperty as a member of VM
- In the Web Client everything is much simpler.
- The script uses the intermediate file
-HelperCsvparameter to export data to the UNICODE format for the correct displaying of non-English characters.
- As you already understood, the script takes the
VM Notesand replicates them to OS
Computer descriptionand/or to AD Computer
It controlled by
-TargetEnvparameter, which can be either
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
- 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-Clustercmdlet and returns a collection of objects with the following properties.
|ComputerName||VM Guest Hostname|
|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
-ErrorOnlyparameter to get only failed records, that contain any error:
Get-Cluster | .\Copy-VMNotes2ComputerDescription.ps1 -ErrorOnly | Format-Table VM, ComputerName, Error –AutoSize
- The best way in my opinion is to export the results on the fly by
-Verbosewill give you some statistical info as well.
Get-Cluster | .\Copy-VMNotes2ComputerDescription.ps1 –Verbose | epcsv –notype –Encoding utf8 .\Report.csv
-Encoding utf8 if your
VM Notes contain non-English characters!
- Pay special attention to the
Errorproperty, it contains an error message if an error occurred. Because these messages can be quite long, especially WMI errors, generated by
Errorwill contain only the first sentence of the error message. This is done using Regex.
- All parameters of the script, except for the
-Clusterparameter, 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
- The script does not correct and does not add anything to the existing
Description. It completely overwrites the
VM with empty
Notesproperty 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
Remote Server Administration Tools).
- Script tries to obtain
VM Guest Hostname, if it fails the
VM Nameused 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