In our production environment, we aim to gather details about virtual machines, such as owner, installation dates, and the server’s purpose. In the past, we relied on adding this information in the VM notes, though it wasn’t the most effective method. Unfortunately, not everyone consistently provided the required information, and I’m also guilty of occasional lapses in completing it.
We’ve recently implemented Infrastructure as Code for deploying new servers, and as part of this initiative, we addressed the need for comprehensive server information. To accomplish this, we introduced VM Custom Attributes. This solution proves to be cleaner and more straightforward, enabling a higher level of standardization. However, it necessitates the elimination of the outdated legacy VM notes.
Create Custom Attributes
Custom attributes offer the capability to assign user-specific information to an object, whether it be a host, virtual machine, cluster, or network. Further details can be found in the documentation.
- In vCenter, open Tags & Custom Attributes
- Click Custom Attributes
- Click New
- Enter the name of the attribute and select the type.
After clicking OK the attribute is added to all objects.
Importing the information.
To eliminate the need for manual importation of information, I devised a PowerShell script that automates the addition of details from a CSV file.
The script: (full script on my Github)
# Import Custom Attributes information from CSV
$servers = import-csv -Path ".\VM_CustomAttributes.csv" -Delimiter ";"
foreach ($server in $servers){
Write-host " Set Attributes for $($server.VMName)" -ForegroundColor Yellow -NoNewline
$vm = Get-VM -Name $server.VMName
$vm | Set-Annotation -CustomAttribute "Service_Request" -Value $server.SR | Out-Null
$vm | Set-Annotation -CustomAttribute "Requestor" -Value $server.Requester | Out-Null
$vm | Set-Annotation -CustomAttribute "Server_Purpose" -Value $server.Description | Out-Null
$vm | Set-Annotation -CustomAttribute "Deploy_date" -Value $server.Install | Out-Null
Write-host " => Attributes Set" -ForegroundColor DarkGreen
}
The csv-file:
VMName; SR; Requester; Description; Install
DC10; 001; MerlevedeN; Domain Controller; 2023-07-2
DFS10; 002; Nick; DFS Server ; 2023-08-16
When de import is done we have the following situation.